We help IT Professionals succeed at work.

Unzip file using 7-zip in C#

asbpenguinman
on
9,189 Views
Last Modified: 2013-12-01
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

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2009

Commented:
and it's probably a good idea to escape your backslashes :)
no need because of @ prefix
Top Expert 2009

Commented:
oops, you're right :P

Author

Commented:
It was the space between the switch and the path that was the issue.  Thanks for the help.
Jaime OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
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
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.