2

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();
spaghettifunk
  • 1,936
  • 4
  • 24
  • 46
wol
  • 21
  • 1
  • 3

2 Answers2

1

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

Monoman
  • 721
  • 10
  • 12
-1

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.

Windows 7 x64 - 7-Zip 9.20

Community
  • 1
  • 1
NET3
  • 1,520
  • 1
  • 16
  • 25