简体   繁体   English

使用 SevenZipSharp 压缩和提取

[英]Compress and Extract with SevenZipSharp

I'm trying to compress and extract files with SevenZipSharp, but I'm getting following error:我正在尝试使用 SevenZipSharp 压缩和提取文件,但出现以下错误:

Can not load 7-zip library or internal COM error!无法加载 7-zip 库或内部 COM 错误! Message: failed to load library.消息:加载库失败。

My code:我的代码:

string extractFrom = @"C:\Test\Test.7z";
string extractTo = @"C:\Test2";

string compressFrom = @"C:\Test2";
string compressTo = @"C:\Test\Test2.7z";

SevenZipBase.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");

SevenZipCompressor compressor = new SevenZipCompressor();
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = Path.GetTempPath();
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
compressor.CompressDirectory(compressFrom, compressTo);//Error

SevenZipExtractor extractor = new SevenZipExtractor(extractFrom);
extractor.ExtractArchive(extractTo);//Error

The error is at:错误在:

compressor.CompressDirectory(compressFrom, compressTo);

and at:并在:

extractor.ExtractArchive(extractTo);

How can I solve this problem?我怎么解决这个问题?

Most obvious answer: the dll is not at the given path.最明显的答案:dll 不在给定的路径上。

But I assume you've tried that, but if you mix 32 bit and 64 bit applications this is also a known issue.但是我假设您已经尝试过,但是如果您混合使用 32 位和 64 位应用程序,这也是一个已知问题。 So if your application is running 32 bits and the 7zip is installed as x64 this error will be thrown.因此,如果您的应用程序运行 32 位并且 7zip 安装为 x64,则会引发此错误。

Also see this: A reference to .dll could not be added.另请参阅: 无法添加对 .dll 的引用。 Please make sure that the file is accessible, and that it is a valid assembly or COM component 请确保该文件是可访问的,并且它是一个有效的程序集或 COM 组件

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

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