Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

7zip

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);
}
like image 754
DanielVest Avatar asked Aug 03 '13 04:08

DanielVest


People also ask

Why do I get a 7-Zip error while downloading?

Downloading error: The error of 7-zip file may also occur while downloading from the internet due to slow connection or bandwidth etc. that can also lead to CRR error. File header corruption: File header is the place to contain the file name, size, and extension, etc. These details help in accessing the file.

Can I compress a folder using 7-Zip?

I've checked everything, I clicked on properties, I have all the permission boxes ticked, other folders are able to be compressed no problem, I can compress the folder using 7-Zip but it isn't able to be uploaded to any websites or anything.

How do i compress a file or folder in Linux?

Locate the file or folder that you want to compress. Right-click the file or folder, point to Send To, and then click Compressed (zipped) Folder. A new compressed folder is created. To rename it, right-click the folder, click Rename, and then type the new name. This thread is locked.

How to get rid of 7-Zip virus on Mac?

Step 1: Use antivirus to clear the virus in the software. You may use quick heal, Norton, or AGV antivirus. Step 2: Then, browse the 7-zip official website to get the tool again. But, before installing the new one, be sure to uninstall the previous version. Always remember to get the same version that you used to compress the file.


1 Answers

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.

like image 198
Vaughan Hilts Avatar answered Oct 03 '22 18:10

Vaughan Hilts