如何使用 SevenZipSharp 将文件添加到存档
首先,我想做的是:
我有一个要添加到同一存档的文件列表。该文件的文件夹结构应包含在存档中。
我遇到的问题是我无法将文件添加到现有存档中。当我使用 CompressionMode.Create 时,只有实际文件位于存档中,当我使用 CompressionMode.Append 时,我收到 KeyNotFoundException 且没有任何更改档案。
SevenZip.SevenZipCompressor szc = new SevenZip.SevenZipCompressor();
if (File.Exists(PathToArchive))
szc.CompressionMode = SevenZip.CompressionMode.Append;
else
szc.CompressionMode = SevenZip.CompressionMode.Create;
FileStream archive = new FileStream(Filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
szc.DirectoryStructure = true;
szc.EncryptHeaders = true;
szc.DefaultItemName = filename; //if the full path given the folders are also created
szc.CompressStream(filestream, archive, Password);
}
catch (Exception e) { }
archive.Close();
First of all what I want to do:
I have a list of files I'd like to add to the same archive. The folder structure to this files should be included to the archive.
The problem I have is that I can not add files to an existing archive. When I use CompressionMode.Create
only the actual file is in the archive, when I use CompressionMode.Append
I get a KeyNotFoundException
and nothing changed on the archive.
SevenZip.SevenZipCompressor szc = new SevenZip.SevenZipCompressor();
if (File.Exists(PathToArchive))
szc.CompressionMode = SevenZip.CompressionMode.Append;
else
szc.CompressionMode = SevenZip.CompressionMode.Create;
FileStream archive = new FileStream(Filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
szc.DirectoryStructure = true;
szc.EncryptHeaders = true;
szc.DefaultItemName = filename; //if the full path given the folders are also created
szc.CompressStream(filestream, archive, Password);
}
catch (Exception e) { }
archive.Close();
我使用 SharpZipLib 0.64(来自 Nuget)和来自 sourceforge 的 7z.dll 9.20 将文件附加到现有存档没有任何问题,但我使用的是 compressfiles() 而不是 compressstream()。
I'm not having any problem to append files to an existing archive, with SharpZipLib 0.64 (from the Nuget) and 7z.dll 9.20 from sourceforge, but I'm using CompressFiles() instead of CompressStream().