我目前正在尝试将SevenZipSharp
功能实现到我的项目中。我已经阅读了他们的文档,并查看了注释的源代码,但我很难弄清楚CompressFilesEncrypted
方法。我收到一个错误,在archiveName参数上显示"访问被拒绝"。
任何成功使用过这个的人,你能给我一些关于如何完成这个实现的建议吗?
这是我正在使用的代码(看起来很简单):
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);
}
任何见解都将不胜感激!我知道肯定有人以前做过这个工作:)
更正了代码并解决了问题。更正了以下代码:
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);
输出目录需要具有正确扩展名的文件名。结果证明是问题的一部分。