How can I create 7-Zip archives from my C# console application? I need to be able to extract the archives using the regular, widely available 7-Zip program.
Here are my results with the examples provided as answers to this question
- "Shelling out" to 7z.exe - this is the simplest and most effective approach, and I can confirm that it works nicely. As workmad3 mentions, I just need to guarantee that 7z.exe is installed on all target machines, which is something I can guarantee.
- 7Zip in memory compression - this refers to compressing cookies "in-memory" before sending to the client; this method seems somewhat promising. The wrapper methods (wrapping the LZMA SDK) return type
byte[]
. When I write thebyte[]
array to a file, I can't extract it using 7-Zip (File.7z is not supported archive
). - 7zSharp Wrapper (found on CodePlex) - this wraps the 7z exe/LZMA SDK. I referenced the project from my app, and it successfully created some archive files, but I was unable to extract the files using the regular 7-Zip program (
File.7z is not supported archive
). - 7Zip SDK aka LZMA SDK - I guess I'm not smart enough to figure out how to use this (which is why I posted here)... Any working code examples that demonstrate creating a 7zip archive that is able to be extracted by the regular 7zip program?
- CodeProject C# (.NET) Interface for 7-Zip Archive DLLs - only supports extracting from 7zip archives... I need to create them!
- SharpZipLib - According to their FAQ, SharpZipLib doesn't support 7zip.
I used the sdk.
eg:
Just Install 7 zip from source and pass the parameter to the method.
Thanks. Please like the answer.
SharpCompress is in my opinion one of the smartest compression libraries out there. It supports LZMA (7-zip), is easy to use and under active development.
As it has LZMA streaming support already, at the time of writing it unfortunately only supports 7-zip archive reading. BUT archive writing is on their todo list (see readme). For future readers: Check to get the current status here: https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md
SevenZipSharp is another solution. Creates 7-zip archives...
EggCafe 7Zip cookie example This is an example (zipping cookie) with the DLL of 7Zip.
CodePlex Wrapper This is an open source project that warp zipping function of 7z.
7Zip SDK The official SDK for 7zip (C, C++, C#, Java) <---My suggestion
.Net zip library by SharpDevelop.net
CodeProject example with 7zip
SharpZipLib Many zipping
These easiest way is to work with .zip files instead of .7z and use Dot Net Zip
When spinning off 7zip commands to shell there are other issues like user privileges, I had issue with SevenZipSharp.