2014-10-17 58 views
0

我的基本目標是這樣的:從URI 啓動文件8.1

  • 保存到獨立存儲
  • 啓動默認的應用程序

    1. 獲取文件

    我已經完成了所有的代碼,「。PDF,.txt」文件也是開放的,但其內容並未出現。它仍然是空白的。在 「.DOCX」 的情況下,我得到這個消息:

    "Document has been damaged and can't be opened". 
    

    見下面我的代碼:

    String file = "abc.pdf"; 
    Uri uri = new Uri("https://www.abc.com/abcd/getDocument"); 
    
    WebClient wc = new WebClient(); 
    wc.OpenReadAsync(uri); 
    wc.OpenReadCompleted += wc_OpenReadCompleted; 
    
    async void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
    { 
         byte[] buffer = new byte[e.Result.Length]; 
         await e.Result.ReadAsync(buffer, 0,(int)buffer.Length); 
    
         using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication()) 
         { 
          using (IsolatedStorageFileStream stream = storageFile.OpenFile(file, FileMode.Create)) 
          { 
           await stream.WriteAsync(buffer, 0, buffer.Length); 
           stream.Flush(); 
          } 
         } 
    
         StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; 
         StorageFile pdffile = await local.GetFileAsync(file); 
    
        // Launch the pdf file 
        await Windows.System.Launcher.LaunchFileAsync(pdffile); 
    
    } 
    
  • 回答

    1

    你的URI是不正確的。嘗試使用正確的URI。這是唯一的問題。您可以通過在瀏覽器中鞠躬使用的URI進行驗證。它不存在。

    對所有文件使用相同的擴展名,例如.pdf用於PDF文件,用於docx文件使用.docx擴展名