“文件已损坏,无法打开”:Windows Phone 8.1

时间:2014-10-30 06:15:25

标签: c# file windows-phone-8.1 isolatedstorage

enter image description here

我正在将文件写入隔离存储并试图启动它但是获得异常 像这样:

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

请参阅我的代码:

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, buffer.Length);

using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (IsolatedStorageFileStream stream = storageFile.OpenFile("Document.docx", FileMode.Create))
    {
       await stream.WriteAsync(buffer, 0, buffer.Length);
    }
}

StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile pdffile = await local.GetFileAsync("Document.docx");

await Windows.System.Launcher.LaunchFileAsync(pdffile);

}

1 个答案:

答案 0 :(得分:1)

您需要先关闭原始stream,然后才能重新打开调用LaunchFileAsync()的文件。