Download the standalone version of the console from 7zip.com and add it to your project.
You need these 3 files added to the project:
- 7za.exe
- 7za.dll
- 7zxa.dll
Do not forget to say "Copy to output directory" in the settings.
Extract archive:
public void ExtractFile(string sourceArchive, string destination)
{
string zPath = "7za.exe";
try
{
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = zPath;
pro.Arguments = string.Format("x \"{0}\" -y -o\"{1}\"", sourceArchive, destination);
Process x = Process.Start(pro);
x.WaitForExit();
}
catch (System.Exception Ex) {
}
}
Create archive:
public void CreateZip(string sourceName, string targetArchive)
{
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7za.exe";
p.Arguments = string.Format("a -tgzip \"{0}\" \"{1}\" -mx=9", targetArchive, sourceName);
p.WindowStyle = ProcessWindowStyle.Hidden;
Process x = Process.Start(p);
x.WaitForExit();
}