Question

I'm currently trying to implement the SevenZipSharp functionality into my project. I've read what documentation they have and checked out the source code for notes but I'm having trouble figuring out the CompressFilesEncrypted method. I'm getting an error that says "Access is Denied" on the archiveName parameter.

Anyone that has used this successfully could you please give me some advice on how to complete this implementation?

Here is the code I'm using (seemed pretty simple):

        string fileName = Path.GetFileName(filepath);
        string outputDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        try
        {
                        SevenZipCompressor compressor = new SevenZipCompressor();
                        compressor.CompressionMethod = CompressionMethod.Default;
                        compressor.CompressionLevel = CompressionLevel.Normal;
                        compressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
                        compressor.ArchiveFormat = OutArchiveFormat.Zip;
                        **compressor.CompressFilesEncrypted(outputDir, "12345",filepath);**
        }
        catch (Exception exc)
        {
            MessageBox.Show(exc.Message);
        }

Any insight is much appreciated! I know someone has to have made this work before :)

Was it helpful?

Solution

Corrected code and issue was resolved. Corrected code below:

SevenZipCompressor compressor = new SevenZipCompressor();
            compressor.CompressionMethod = CompressionMethod.Deflate;
            compressor.CompressionLevel = CompressionLevel.High;
            compressor.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
            compressor.ArchiveFormat = OutArchiveFormat.Zip;
            compressor.CompressionMode = CompressionMode.Create;
            compressor.EventSynchronization = EventSynchronizationStrategy.AlwaysAsynchronous;
            compressor.FastCompression = false;
            compressor.EncryptHeaders = true;
            compressor.ScanOnlyWritable = true;
            compressor.CompressFilesEncrypted(outputDir, password, filepath);

Output directory requires filename with proper extension. Turned out to be part of the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top