21

There is a similar question for 3.5 here:

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

that speculated that 4.0 would have it, but I can't find any info about it. If not, does anyone know why not? Seems like it would be fairly high on the list of things to include support for.

Community
  • 1
  • 1
Jason
  • 11,435
  • 24
  • 77
  • 131
  • 1
    Looking for [`System.IO.Compression`](http://msdn.microsoft.com/en-us/library/system.io.compression.aspx)? – pickypg May 10 '11 at 04:40
  • 3
    no: "... this class does not inherently provide functionality for adding files to or extracting files from .zip archives." – user492238 May 10 '11 at 04:47
  • True, but it still enables you to roll your own. If you search around for "GZipStream multiple files" you'll see a lot of people have done just that. – pickypg May 10 '11 at 04:55
  • 1
    The top result I saw for that search is a "roll your own" format that combines multiple files and then gzips them. Doesn't make much sense to me. Why re-invent .tar.gz? There are good tar libraries out there for .NET, they do gzip (using GZipStream), and they are interoperable with a format and a bunch of tools that have been around since 1996. Why invent something different? – Cheeso May 11 '11 at 04:18

4 Answers4

15

Take a look at the System.IO.Packaging namespace, which contains support for ZIP files, but not all of the features of ZIP files.

Still, it might be enough for your needs.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Attempting to use these classes, I found they were able to work with things like Nuget-packages and similar "bundles" (probably XAP-files too) but unable to parse regular ZIP-files as such. If your use-case is limited to parsing these sorts of files, the System.IO.Packaging namespace should be sufficient. – Jostein Kjønigsen Jun 03 '14 at 11:38
10

You may have already moved along, but ZiP API is added in .NET 4.5

http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.aspx

go nuts.

Madushan
  • 6,977
  • 31
  • 79
9

Not for 4.0, but a ZipArchive class is being considered for the next version. You can find details about this on the BCL Team blog.

Edit: Otherwise, assuming that it's still available, and depending on your definition of built in (at least it comes/came with Visual Studio), you might be able to use the J# classes to zip files as described in this article: Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#

Edit2: Though note the comments below, that the J# option is probably not the right option except in certain unusual circumstances.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • 3
    Ohmygosh no, don't use the J# libraries. They are out of support now, if I am not mistaken, for about 4 years. Also based on Java 1.1.4, and NO security fixes in any of them. Use a real zip library. – Cheeso May 11 '11 at 04:16
  • @Cheeso: I wouldn't recommend it in general, I use sharpziplib myself, but I know that there can sometimes be companies that doesn't allow those kind of libraries but might be ok with using the J# libraries since they came with VS, so in certain situations using an older version of VS, it might be an option. – Hans Olsson May 12 '11 at 20:47
-2

Most easiest to deal with, is with sample code here.

You need to add a new assembly just to find he Zip archive.

Working with Zip files in .NET 4.5

abhishek
  • 2,975
  • 23
  • 38