wol
wol

Reputation: 31

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

Upvotes: 3

Views: 4482

Answers (2)

Monoman
Monoman

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

NET3
NET3

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.

Windows 7 x64 - 7-Zip 9.20

Upvotes: -1

Related Questions