I referenced to my project the dll file: SevenZipSharp.dll
我引用了我的项目的dll文件:7 zipsharp .dll。
Then in the top of Form1 I added:
在Form1的顶部,我添加了:
using SevenZip;
Then I created a function that I'm calling from a button click event:
然后我创建了一个从按钮点击事件中调用的函数:
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);
}
I used a breakpoint and the error is on the line:
我用了一个断点,这个错误在直线上:
compressor.CompressDirectory(source, output);
But I'm getting an error:
但是我有一个错误
Cannot load 7-zip library or internal COM error! Message: DLL file does not exist
无法加载7-zip库或内部COM错误!消息:DLL文件不存在。
But I referenced the dll already, so why this error? How can I fix it?
但是我已经引用了这个dll,为什么会出现这个错误呢?我怎样才能修好它?
Solved the problem:
解决了这个问题:
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);
}
4 个解决方案
#1
3
You're probably missing the internal COM component that is required. If you check the InnerException, it should give you a good idea of what's missing. Copy these to your working directory and you should be set.
您可能丢失了所需的内部COM组件。如果您检查了内部异常,它应该会让您了解丢失了什么。将这些复制到您的工作目录中,您应该被设置。
#2
2
As mentioned at the end of the OP's post, you need to set the library path. But to overcome the uniqueness of the environment, you could always use reflection to set the path to the DLL. As long as the 7z.dll is in the project's bin folder, this will get you the path to it.
正如OP的文章末尾提到的,您需要设置库路径。但是为了克服环境的唯一性,您可以一直使用反射来设置DLL的路径。只要7z。dll在项目的bin文件夹中,这会让你找到它的路径。
add this to your using statements:
将此添加到您的using语句:
using System.Reflection;
Then set the path like this:
然后像这样设置路径:
SevenZipCompressor.SetLibraryPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll"));
#3
1
Copy 7z.dll (32bit version) to working directory. This exception sometimes thrown in the 64-bit version.
副本7 z。dll(32位版本)到工作目录。这个异常有时会出现在64位版本中。
#4
0
This is working well & max compress method ever.the bast solution.
这是有效的和最大压缩方法。韧皮的解决方案。
- give writing access to the output folder or drive.
- 对输出文件夹或驱动器进行写入访问。
- install 7 zip software into your pc
- 在你的电脑上安装7个zip软件。
Function:
功能:
private void Compress()
{
string source = "E:\\w";
string output = "E:\\3.7z";
string programFiles1 = "C:\\Program Files\\7-Zip\\7z.dll";
if (File.Exists(programFiles1))
{
SevenZipExtractor.SetLibraryPath(programFiles1);
}
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
compressor.CompressionMode = SevenZip.CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
compressor.CompressDirectory(source, output);
}
#1
3
You're probably missing the internal COM component that is required. If you check the InnerException, it should give you a good idea of what's missing. Copy these to your working directory and you should be set.
您可能丢失了所需的内部COM组件。如果您检查了内部异常,它应该会让您了解丢失了什么。将这些复制到您的工作目录中,您应该被设置。
#2
2
As mentioned at the end of the OP's post, you need to set the library path. But to overcome the uniqueness of the environment, you could always use reflection to set the path to the DLL. As long as the 7z.dll is in the project's bin folder, this will get you the path to it.
正如OP的文章末尾提到的,您需要设置库路径。但是为了克服环境的唯一性,您可以一直使用反射来设置DLL的路径。只要7z。dll在项目的bin文件夹中,这会让你找到它的路径。
add this to your using statements:
将此添加到您的using语句:
using System.Reflection;
Then set the path like this:
然后像这样设置路径:
SevenZipCompressor.SetLibraryPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll"));
#3
1
Copy 7z.dll (32bit version) to working directory. This exception sometimes thrown in the 64-bit version.
副本7 z。dll(32位版本)到工作目录。这个异常有时会出现在64位版本中。
#4
0
This is working well & max compress method ever.the bast solution.
这是有效的和最大压缩方法。韧皮的解决方案。
- give writing access to the output folder or drive.
- 对输出文件夹或驱动器进行写入访问。
- install 7 zip software into your pc
- 在你的电脑上安装7个zip软件。
Function:
功能:
private void Compress()
{
string source = "E:\\w";
string output = "E:\\3.7z";
string programFiles1 = "C:\\Program Files\\7-Zip\\7z.dll";
if (File.Exists(programFiles1))
{
SevenZipExtractor.SetLibraryPath(programFiles1);
}
SevenZipCompressor compressor = new SevenZipCompressor();
compressor.ArchiveFormat = OutArchiveFormat.SevenZip;
compressor.CompressionMode = SevenZip.CompressionMode.Create;
compressor.TempFolderPath = System.IO.Path.GetTempPath();
compressor.CompressDirectory(source, output);
}