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();