DanielVest DanielVest - 1 month ago 5
C# Question

I'm trying to compress some files using SevenZipSharp but getting an error

I referenced to my project the dll file:

SevenZipSharp.dll


Then in the top of Form1 I added:

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


But I referenced the dll already, so why this error? How can I fix it?

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);
}

Answer

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.

Comments