我正在尝试解压缩文件,但我总是有
Access to the path 'C:\Users\Kosov Denis\Downloads\12.epub' is denied.
我穿了什么?
await Task.Run(() =>
{
ZipFile.ExtractToDirectory(file.Path,
ApplicationData.Current.LocalCacheFolder.Path +
string.Format(@"\{0}", file.Name.Replace(file.FileType, "")));
});
最佳答案
我也遇到过和你一样的问题,我google了半天发现UWP好像不能直接通过路径访问文件,如果要访问本地文件,需要使用文件拾取,见: hele . 我用曲线来解决这个问题:
StorageFolder folder;
folder = ApplicationData.Current.LocalFolder;
//Open the file picker
var _openFile = new FileOpenPicker();
_openFile.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
_openFile.ViewMode = PickerViewMode.List;
_openFile.FileTypeFilter.Add(".zip");
StorageFile file = await _openFile.PickSingleFileAsync();
//Read the file stream
Stream a = await file.OpenStreamForReadAsync();
//unzip
ZipArchive archive = new ZipArchive(a);
archive.ExtractToDirectory(folder.Path);
关于c# - 如何在UWP中解压文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38090269/