Reputation: 31
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();
Upvotes: 3
Views: 4482
Reputation: 731
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().
Upvotes: 1
Reputation: 1570
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.
Upvotes: -1