Link to home
Start Free TrialLog in
Avatar of asbpenguinman
asbpenguinman

asked on

Unzip file using 7-zip in C#

I am trying to use the 7-zip command line utility to unzip a file in a C# program.  I am having problems, however, getting it to unzip.
public static void Unzip(DirectoryInfo DirecInfo)
{
   if (DirectInfo.Exists)
   {
       foreach (FileInfo fileInfo in DirecInfo.GetFiles("*.zip"))
       {
           Process process = new Process();
           process.StartInfo.FileName = @"C:\Program Files\7-zip\7z.exe";
           process.StartInfo.Arguments = @" e C:\Directory\" + fileInfo.Name + @" -o C:\Directory";
           process.Start();
       }
   }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zveljkovic
zveljkovic
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and it's probably a good idea to escape your backslashes :)
no need because of @ prefix
oops, you're right :P
Avatar of asbpenguinman
asbpenguinman

ASKER

It was the space between the switch and the path that was the issue.  Thanks for the help.
have a look to this article:
http://www.codeproject.com/KB/DLL/cs_interface_7zip.aspx

You will gain more control over 7zip working with the dll, than invoking the .exe