How do I update existing archive with the password protection?

Mar 6, 2011 at 3:06 PM
Edited Mar 6, 2011 at 3:09 PM

Hi all,

I'm running with a problem related to updating existed 7z archive with the password protection.

There is a function, which I'm using:

public void ArchiveFile (string filePath) {
    string pathZip = @"C:\test.7z";
    string pwd = "test";

    SevenZip.SevenZipCompressor.SetLibraryPath(Application.StartupPath + "\\" + "7z.dll");
    SevenZip.SevenZipCompressor zipFile = new     SevenZipCompressor(); 
    zipFile.ArchiveFormat = OutArchiveFormat.SevenZip; 
    zipFile.CompressionLevel = CompressionLevel.None;
    zipFile.EncryptHeaders = true;
    if (File.Exists(pathZip))
        zipFile.CompressionMode = CompressionMode.Append;
    else
       zipFile.CompressionMode = CompressionMode.Create;
    zipFile.CompressFilesEncrypted(pathZip, pwd, filePath);
}

When archive does not exist the function will create an archive, and it will put the filePath inside.

But if I invoke it again whith another filePath the archive will be deleted and the function will throw an exception:

"Invalid archive: open/read error! Is it encrypted and a wrong password was provided?If your archive is an exotic one, it is possible that SevenZipSharp has no signature for its format and thus decided it is TAR by mistake. Message: Can not update the archive: Open() failed."

 

So, can somebody help me?

Thanks :)