2012-12-16 26 views
0

我使用直播API下載SkyDrive中文件。下載並啓動默認的應用程序在Windows 8手機

我的代碼有一個下載點擊事件觸發了OnDownloadedCompleted函數。

OnDownloadedCompleted函數將文件複製到「文件名」。

,並調用DefaultLaunch(),這需要在「文件名」,並試圖通過預設程序在Windows 8手機

啓動它,當我執行代碼(下載的文件是一個OneNote文件)OneNote將打開並顯示文件無法打開。

任何人都可以幫我驗證這段代碼嗎?

非常感謝!

private void btnDownload_Click(object sender, RoutedEventArgs e) 
    { 

     if (App.Current.LiveSession == null) 
     { 
      infoTextBlock.Text = "You must sign in first."; 
     } 
     else 
     { 
      LiveConnectClient client = new LiveConnectClient(App.Current.LiveSession); 
      client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompleted); 

      client.DownloadAsync("file_id"); 

     } 
    } 

爲OnDownloadCompleted的代碼是

void OnDownloadCompleted(object sender, LiveDownloadCompletedEventArgs e) 
    { 
     if (e.Result != null) 
     { 
      var filestream = File.Create(@"filename"); 
      e.Result.Seek(0, SeekOrigin.Begin); 
      e.Result.CopyTo(filestream); 
      filestream.Close(); 
      DefaultLaunch(); 

      e.Result.Close(); 

     } 
     else 
     { 
      infoTextBlock.Text = "Error downloading image: " + e.Error.ToString(); 
     } 
    } 

爲默認的啓動函數的代碼是

async void DefaultLaunch() 
    { 

     try 
     { 
      string imageFile = @"File.one"; 
      var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile); 
      var success = await Windows.System.Launcher.LaunchFileAsync(file); 
      if (success) 
      {} 
      else 
      {} 
     } 
     catch (Exception e) 
     { 
      Console.WriteLine(e.StackTrace); 
      Console.WriteLine(e.ToString()); 

     } 
    } 
+0

如何' 「文件名」'和' 「File.one」'相同˚F ilename? –

回答

1

試試這個教程.. http://msdn.microsoft.com/en-us/live/ff519582.aspx ..它被賦予有如何使用直播SDK在Windows 8平臺

+0

嘿其實我試着使用測試數據,並給名稱File.one。它的實際文件名。 – rtshmittl

+0

zedray - 請你具體一下。謝謝你的時間! – rtshmittl

+0

嘿,我通過在文件ID後面加上「/ content」來實現代碼。現在它正在工作,但是我無法打開「.onepkg」格式的文件。理想情況下,他們應該在OneNote中打開,但它會讓我在商店中找到一個應用程序。任何建議/指針?謝謝你的幫助! – rtshmittl

相關問題