views:

1898

answers:

9

Hello everyone,

Looks like no built-in Library/API in C# to unzip a zip file. I am looking for a free (better open source) library/API which could work with .Net 3.5 + VSTS 2008 + C# to unzip a zip file and extract all files into a specific folder.

Any recommended library/API or samples?

thanks in advance, George

+11  A: 

The LGPL

http://www.icsharpcode.net/OpenSource/SharpZipLib/

OR the less restrictive Ms-PL

http://www.codeplex.com/DotNetZip

To complete this answer the .net framework has ZipPackage I had less success with it.

Sam Saffron
as well .Net has a built in implementation, but its impossible to work with
Sam Saffron
Cool I like the first one. For the .Net one, which class do you mean?
George2
Why do you mean .Net ZipPackage is less success?
George2
See: http://stackoverflow.com/questions/507751/extracting-files-from-a-zip-archive-programmatically-using-c-and-system-io-packa
Sam Saffron
In most cases, DotNetZip is considerably simpler to use that SharpZipLib.
Cheeso
+1  A: 

Look for System.IO.Compression.GZipStream & System.IO.Compression.DeflateStream

shahkalpesh
it wont work you need to parse the header to get zip file format support
Sam Saffron
Hmm. I haven't used the GZipStream/DeflateStream, but I knew of such a class in namespace. Thanks for letting me know of that.
shahkalpesh
@Sam, could you explain what do you mean -- "it wont work you need to parse the header to get zip file format support" please?
George2
GZipStream and DeflateStream DO NOT read or write zip files. Check the doc. http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx -- "this class does not inherently provide functionality for adding files to or extracting files from .zip archives."
Cheeso
shahkalpesh
+4  A: 

SharpZipLib

http://www.icsharpcode.net/OpenSource/SharpZipLib/

Henri
How do you think of .Net's built ZipPackage class?
George2
+1  A: 

If you want to use 7-zip compression, check out Peter Bromberg's EggheadCafe article. Beware: the LZMA source code for c# has no xml comments (actually, very few comments at all).

C-Pound Guru
+5  A: 

DotNetZip is easy to use. Here's an unzip sample

using (var zip = Ionic.Zip.ZipFile.Read("archive.zip")
{
   zip.ExtractAll("unpack-directory");
}

If you have more complex needs, like you want to pick-and-choose which entries to extract, or if there are passwords, or if you want to control the pathnames of the extracted files, or etc etc etc, there are lots of options. Check the help file for more examples.

DotNetZip is free and open source.

Cheeso
+2  A: 

In the past, I've used DotNetZip (MS-PL), SharpZipLib (GPL), and the 7ZIP SDK for C# (public domain). They all work great, and are open source.

I would choose DotNetZip in this situation, and here's some sample code from the C# Examples page:

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
  foreach (ZipEntry e in zip)
  {
    e.Extract(TargetDirectory);
  }
}
Maxim Zaslavsky
A: 

I would prefer SharpZiplib Please find the sample code to UnZip Files in .Net C#

A: 

Have a look to my small library: http://zipstorer.codeplex.com

Jaime Olivares
A: 

I would recommend our http://www.rebex.net/zip.net/ but I'm biased. Download trial and check the features and samples yourself.

Martin Vobr