C# 如何在UWP中解压缩文件

C# 如何在UWP中解压缩文件,c#,zip,uwp,C#,Zip,Uwp,我正在尝试解压文件,但我总是 访问路径“C:\Users\Kosov Denis\Downloads\12.epub”的权限为 否认 我做了什么 await Task.Run(() => { ZipFile.ExtractToDirectory(file.Path, ApplicationData.Current.LocalCacheFolder.Path +

我正在尝试解压文件,但我总是

访问路径“C:\Users\Kosov Denis\Downloads\12.epub”的权限为 否认

我做了什么

await Task.Run(() =>
            {
                ZipFile.ExtractToDirectory(file.Path,
                    ApplicationData.Current.LocalCacheFolder.Path +
                    string.Format(@"\{0}", file.Name.Replace(file.FileType, "")));
            });

我也遇到了与您相同的问题,我的google很长时间发现UWP似乎没有直接通过路径访问文件,如果您想访问本地文件,您需要使用文件拾取,请参阅:。 我用曲线来解决这个问题:

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);

我也遇到了与您相同的问题,我的google很长时间发现UWP似乎没有直接通过路径访问文件,如果您想访问本地文件,您需要使用文件拾取,请参阅:。 我用曲线来解决这个问题:

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);

这是uwp应用程序中您可以访问哪些文件夹和目录的访问权限问题。这是uwp应用程序中您可以访问哪些文件夹和目录的访问权限问题。