を圧縮できませんでした。私はフォルダとその内容(サブフォルダ、画像、テキストファイル)を圧縮しようとしています。は私がUWPアプリ(ユニバーサルWindowsのプラットフォーム)を持っているUWP(Windowsの10 APP)での空白のテキストファイル(サイズ0キロバイト)C#
テキストファイルが空でない場合はうまく動作します。
しかし、任意のテキストファイルが空白または空(0キロバイトのサイズ)であるときには、例外を提供します。続き
は誤りです:
{System.ArgumentException: The specified buffer index is not within the buffer capacity. at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source, UInt32 sourceIndex, Int32 count) at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(IBuffer source) at SmartflowRuntimes.Service.d__54.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at SmartflowRuntimes.Service.d__54.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at SmartflowRuntimes.Service.d__53.MoveNext()}
これは私のコードです:
public async Task<string> ZipHelper(string zipFileName)
{
try
{
string appFolderPath = ApplicationData.Current.LocalFolder.Path;
StorageFolder destnFolder = await StorageFolder.GetFolderFromPathAsync(appFolderPath + "\\destn");
StorageFolder sourceFolder = await StorageFolder.GetFolderFromPathAsync(appFolderPath + "\\src");
StorageFile zipFile = await destnFolder.CreateFileAsync(zipFileName, CreationCollisionOption.ReplaceExisting);
Stream zipToCreate = await zipFile.OpenStreamForWriteAsync();
ZipArchive archive = new ZipArchive(zipToCreate, ZipArchiveMode.Update);
await ZipFolderContents(sourceFolder, archive, sourceFolder.Path);
archive.Dispose();
return "success";
}
catch (Exception ex)
{
return "fail";
}
}
public async Task ZipFolderContents(StorageFolder sourceFolder, ZipArchive archive, string baseDirPath)
{
IReadOnlyList<StorageFile> files = await sourceFolder.GetFilesAsync();
foreach (StorageFile file in files)
{
ZipArchiveEntry readmeEntry = archive.CreateEntry(file.Path.Remove(0, baseDirPath.Length));
byte[] buffer = WindowsRuntimeBufferExtensions.ToArray(await FileIO.ReadBufferAsync(file));
using (Stream entryStream = readmeEntry.Open())
{
await entryStream.WriteAsync(buffer, 0, buffer.Length);
}
}
IReadOnlyList<StorageFolder> subFolders = await sourceFolder.GetFoldersAsync();
if (subFolders.Count() == 0) return;
foreach (StorageFolder subfolder in subFolders)
await ZipFolderContents(subfolder, archive, baseDirPath);
}
は、この問題の周りのすべての作業はありますか?ありがとう。