0

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 :)

Encryption
  • 1,809
  • 9
  • 37
  • 52
  • I didnt understand which line gives you an exception? Are you sure you have permissions to write in My documents from your application? – d1mitar Feb 21 '13 at 23:29
  • 1
    The CompressFilesEncrypted throws an error on outputDir - Access Denied. I write to MyDocuments throughout this program so I'm sure I have access. – Encryption Feb 21 '13 at 23:36
  • How about the file name? Is it valid? – Alireza Noori Feb 21 '13 at 23:43
  • yes, everything is valid. I just got it to zip the file by using a different method "BeginCompressFilesEncrypted". But now it is corrupting the file whenever I unzip it. Anyone used this SevenZipSharp before? – Encryption Feb 21 '13 at 23:48

1 Answers1

0

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.

Encryption
  • 1,809
  • 9
  • 37
  • 52