我对 WinRT 开发平台有点陌生,它已经让我发疯了(我是一名长期的 .Net 开发人员,所有那些被删除的 API 都很烦人)我在压缩所有文件时遇到问题Windows.Storage.ApplicationData.Current.TemporaryFolder 这是我当前的代码(VB.Net,基于 MSDN 代码,“文件”是我将所有文件放入的 zip 文件):
Using zipMemoryStream As New MemoryStream()
Using zipArchive As New Compression.ZipArchive(zipMemoryStream, Compression.ZipArchiveMode.Create)
For Each fileToCompress As Windows.Storage.StorageFile In (Await Windows.Storage.ApplicationData.Current.TemporaryFolder.GetFilesAsync())
Dim buffer As Byte() = WindowsRuntimeBufferExtensions.ToArray(Await Windows.Storage.FileIO.ReadBufferAsync(fileToCompress))
Dim entry As ZipArchiveEntry = zipArchive.CreateEntry(fileToCompress.Name)
Using entryStream As Stream = entry.Open()
Await entryStream.WriteAsync(buffer, 0, buffer.Length)
End Using
Next
End Using
Using zipStream As Windows.Storage.Streams.IRandomAccessStream = Await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite)
Using outstream As Stream = zipStream.AsStreamForWrite()
Dim buffer As Byte() = zipMemoryStream.ToArray()
outstream.Write(buffer, 0, buffer.Length)
outstream.Flush()
End Using
End Using
End Using
它构建得很好,但是当我启动代码时,出现异常:UnauthorizedAccessException:访问被拒绝。(HRESULT 异常:0x80070005 (E_ACCESSDENIED))在线:WindowsRuntimeBufferExtensions.ToArray(blahblah... 我想知道怎么了。知道吗?
提前致谢 !