我正在尝试将文件夹的内容归档到一个 zip 文件中。内容主要是大图像。我正在尝试使用此代码执行此操作:
var folderPicker =
new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation =
Windows.Storage.Pickers.PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add("*");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
StorageFile zipFile = await folder.CreateFileAsync(ThemeName.Text + ".zip",
Windows.Storage.CreationCollisionOption.GenerateUniqueName);
Stream themeZipFile = await zipFile.OpenStreamForWriteAsync();
ZipArchive archive = new ZipArchive(themeZipFile);
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFolder temp = await localFolder.GetFolderAsync("Temp");
var files = await temp.GetFilesAsync();
foreach (var item in files)
{
archive.CreateEntryFromFile(item.Path, item.Name);
}
}
但是,在执行时,我收到一个错误:
IOException: 无法寻找为负的绝对流位置。
现在,当我尝试此代码时:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
var folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
folderPicker.FileTypeFilter.Add("*");
StorageFolder folder =
await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
StorageFile zipFile =
await folder.CreateFileAsync(ThemeName.Text + ".zip", Windows.Storage.CreationCollisionOption.GenerateUniqueName);
await Task.Run(() => ZipFile.CreateFromDirectory(localFolder.Path, zipFile.Path));
}
我知道我选择的任何文件夹都被拒绝访问!我怎样才能解决这个问题,将几个较大的文件合并到一个档案中?
守着星空守着你
幕布斯7119047
子衿沉夜
相关分类