我引用了我的项目的 dll 文件:SevenZipSharp.dll
然后在 Form1 的顶部我添加了:
using SevenZip;
然后我创建了一个从按钮单击事件调用的函数:
private void Compress()
{
string source = @"C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_02-08-13";
string output = @"D:\Zipped.zip";
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.Zip;
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
compressor.CompressDirectory(source, output);
}
我使用了一个断点,错误就在这条线上:
compressor.CompressDirectory(source, output);
但我收到一个错误:
无法加载 7-zip 库或内部 COM 错误!消息:DLL 文件不存在
但是我已经引用了dll,为什么会出现这个错误?我该如何解决?
解决了问题:
private void Compress()
{
string source = @"C:\Users\bout0_000\AppData\Local\Diagnostic_Tool_Blue_Screen\Diagnostic Tool Blue Screen\SF_02-08-13";
string output = @"D:\Zipped.zip";
SevenZipExtractor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.Zip;
compressor.CompressionMode = CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
compressor.CompressDirectory(source, output);
}