0
我的基本目標是這樣的:從URI 啓動文件8.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);
}