2016-06-29 43 views
0

我想解压缩文件,但我始终有如何解压缩文件中UWP

访问路径“C:\用户\ Kosov丹尼斯\下载\ 12.epub”是 拒绝。

我在做什么?

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

这是UWP应用程序访问权限问题[点击这里阅读](http://stackoverflow.com/questions/33082835/windows-10-通用应用程序文件目录访问)您可以访问的文件夹和目录。 – Irfan

回答

2

我也遇到了同样的问题和你在一起,我很长一段时间谷歌发现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