使用UWP应用程序。该应用程序的一部分是根据打包成Zip文件的图片创建主题。 这是文件选择器和解压缩过程。
private async void FilePickerWallpaperDynamic(object sender, RoutedEventArgs e)
{
try
{
FileOpenPicker pickerWallpaperDynamic = new FileOpenPicker
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary
};
pickerWallpaperDynamic.FileTypeFilter.Add(".zip");
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFolder createdynamicFolder = await localFolder.CreateFolderAsync("Dynamic", CreationCollisionOption.OpenIfExists);
StorageFolder dynamicFolder = await localFolder.GetFolderAsync("Dynamic");
StorageFile fileName = await pickerWallpaperDynamic.PickSingleFileAsync();
if (fileName != null)
{
selectedDynamicThemeName = Path.GetFileNameWithoutExtension(fileName.Name);
StorageFolder addedTheme = await dynamicFolder.CreateFolderAsync(selectedDynamicThemeName, CreationCollisionOption.ReplaceExisting);
await ExtractToDirectoryAsync(fileName.Path, addedTheme.Path);
}
else
{
}
}
catch (Exception exception)
{
}
}
public static async Task ExtractToDirectoryAsync(string zipFilePath, string destinationDir)
{
await Task.Run(() => ZipFile.ExtractToDirectory(zipFilePath, destinationDir));
}
该应用程序已成功设置正确的路径和名称。但是,当从内部存储器的本地库中选择一个zip文件时,我会看到一条消息,指出访问被拒绝。从可移动存储中尝试时,应用程序崩溃。
答案 0 :(得分:0)
问题在于该文件太大,无法使用Zip函数。 这是要走的路:
settings.Values["Theme"] = selectedDynamicThemeName;
Stream themeZipFile = await fileName.OpenStreamForReadAsync(); ;
ZipArchive archive = new ZipArchive(themeZipFile);