How to add files to archive using SevenZipSharp
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();
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().
This Operation is NOT supported by 7-Zip, even when using its file manager. I suggest you just delete the old archive and recreate it with new files.
精彩评论