【问题标题】:How to unzip file in UWP如何在 UWP 中解压文件
【发布时间】:2016-10-31 14:39:40
【问题描述】:

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

访问路径 '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, "")));
            });

【问题讨论】:

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

标签: c# zip uwp


【解决方案1】:

我也遇到了和你一样的问题,我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);

ZipArchive Class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 2010-10-16
    • 2012-11-21
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 2021-03-15
    • 2017-01-19
    相关资源
    最近更新 更多