32

Is there a built-in zip library in .NET 3.5?

If not, what are the popular open source .net zip libraries.

9 Answers 9

32

EDIT: See note in comments - SharpZipLib is now unmaintained, and you probably want to avoid it.

Open source: #ZipLib

I believe that the classes in the System.IO.Compression namespace are fine for compressing/decompressing a single stream of data, but there's nothing built into the framework to cope with actual zip files.

EDIT: As noted in Ants' answer, there's System.IO.Packaging.ZipPackage but it certainly looks like that's really designed for use in WPF, and wouldn't be terribly convenient to use for general zip file handling. Worth looking into though. I wasn't aware of it before though... definitely worth investigating.

Sign up to request clarification or add additional context in comments.

7 Comments

isn't c# 4.0 going to natively support this? i thought I had read that somewhere. But I have used ZipLib before with success.
I don't know whether .NET 4.0 will have support for this - I wouldn't be surprised. It's still a way off though :)
I found that the SharpZipLib API can be more complicated than it needs to be. Also it is much more than zip - tar, bzip, and i don't know what else. Maybe "too much" if you just want zip. Last, are some things missing? like progress events? AES? maybe these are coming. I'm not aware.
I'm not sure how ZipPackage would be inconvenient. All you need is a library which allows adding files to a zip and retrieving from a zip. How complex could you possibly need it? Also can you elaborate on why it looks like it's for WPF?
@TheMuffinMan: The problem is that ZipPackage is complex, compared with that set of requirements - relationships, parts etc. It's part of a bigger packaging framework. As for the relationship to WPF - that was mostly on the basis of what else is in WindowsBase.dll, most of which seems to be WPF-related.
|
24

There is no built-in library. There are open-source options.

DotNetZip is one. Simple, easy to use. It has good features: AES Encryption, regular encryption, streams, ZIP64, file comments, Unicode, progress events, more. And it's free and open source.

Here's some sample code.

 // extract all Photoshop files larger than 100mb using (ZipFile zip1 = ZipFile.Read(ZipFileName)) { var LargePhotoShopFiles = zip1.SelectEntries("name = *.psd and size > 100mb"); foreach (ZipEntry e in LargePhotoShopFiles) { if (e.UsesEncryption) e.ExtractWithPassword("unpackDirectory", "VerySecret!"); else e.Extract("unpackDirectory"); } } 

5 Comments

I'm very impressed with this library. Using it with great success now - thanks for the heads up.
@Chesso, from 3.5 you have new zip library at msdn.microsoft.com/en-us/library/…
Avram, System.IO.Packaging is not a real zip library.
@Cheeso How is it not a 'real' zip library? What doesn't it do that is expected of any zip library?
Looks like the original source that's linked to in this answer is a bit stale now, with the last update being July '11. Here's a fork of it that has newer bug fixes and is available through NuGet: github.com/haf/DotNetZip.Semverd
10

Check out System.IO.Packaging.ZipPackage class.

2 Comments

This requires things to be in a package format which requires an XML file inside the zip file that defines the layout. It's not a general purpose zip library.
There are problems to find it on standard reference .Net lib, ( blogs.msdn.com/b/dmahugh/archive/2006/12/14/… )
6

7Zip will help and its available in multiple languages

1 Comment

The LZMA SDK you linked to is does not read or write ZIP files. It might be possible to use the 7Zip DLLs, but I'm not sure if there's documentation on that...
4

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

Comments

1

Try System.IO.Compression.DeflateStream.

1 Comment

No, DeflateStream doesn't do ZIP files. Just FYI, neither does the built-in GZipStream. Also, both these streams can exhibit anomalous compression behavior with previously-compressed or incompressible data. They can actually increase the size of the data. you've been warned!
1

I will be second to recommend http://www.7-zip.org/sdk.html LZMA SDK, but it's not ZIP.

  1. It's in public domain
  2. It's FAST on decompression
  3. It has fully managed implementation
  4. It's much better compressing than ZIP/RAR
  5. It has very small footprint
  6. It can work as a stream

1 Comment

Doesn't answer the request. The question was about zip libraries, not alternatives to zip libraries. In many case the specs are set for you, or you are working with a third party component which produces a certain spec.
1

System.IO.Compression has ZipArchive class as of .Net 4.5.

Comments

0

You can extract a zip using this:

 public static void UnZip(string zipFile, string folderPath) { if (!File.Exists(zipFile)) throw new FileNotFoundException(); if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath); var t = Type.GetTypeFromProgID("Shell.Application"); dynamic shellApplication = Activator.CreateInstance(t); dynamic destinationFolder = shellApplication.NameSpace(folderPath); dynamic sourceFile = shellApplication.NameSpace(zipFile); foreach (var file in sourceFile.Items()) { destinationFolder.CopyHere(file, 4 | 16); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.