简体   繁体   English

使用C#SevenZipSharp-压缩错误

[英]Using C# SevenZipSharp - Errors on Compress

I'm currently trying to implement the SevenZipSharp functionality into my project. 我目前正在尝试在我的项目中实现SevenZipSharp功能。 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. 我已经阅读了他们拥有的文档,并签出了注释的源代码,但是我在弄清楚CompressFilesEncrypted方法时遇到了麻烦。 I'm getting an error that says "Access is Denied" on the archiveName parameter. 我在archiveName参数上收到一条错误消息,提示“访问被拒绝”。

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 :) 我知道有人必须先完成这项工作:)

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. 原来是问题的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM