如何解压缩UWP中的文件
本文关键字:文件 UWP 解压缩 | 更新日期: 2023-09-27 17:53:17
我试图解压缩文件,但我总是有
访问路径"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似乎不能直接通过路径访问文件,如果要访问本地文件,就需要使用文件拾取,参见: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类