Search code examples
c#unzip7zip

Unzip a file in c# using 7z.exe


I'm trying to unzip a file from a winform application. I'm using this code :

string dezarhiverPath = @AppDomain.CurrentDomain.BaseDirectory + "\\7z.exe";
ProcessStartInfo pro = new ProcessStartInfo();
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = dezarhiverPath;
pro.Arguments = @" e c:\TEST.ZIP";
Process x = Process.Start(pro);
x.WaitForExit();

The code doesn't return error but doesn't anything. I tried this command also from cmd :

K:\>"C:\Test\7z.exe" e "c:\TEST.ZIP" 

but in cmd ,I receive this error message :

7-Zip cannot find the code that works with archives.

Can somebody help me to unzip some files from c# ?

Thanks!


Solution

  • Why would you bother trying to use the 7z.exe application externally? That is a very kludgy way of doing it. Instead use one of the many libraries at your disposal.

    If this is a new application, and you are targeting .NET 4.5, The new System.IO.Compression namespace has a ZipFile class.

    Alternatively, SharpZipLib is a GPL library for file compression in .NET. There are online samples.

    Also available is DotNetZip which is Ms-PL licensed.