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.

4
  • 1
    Looking for System.IO.Compression?
    – pickypg
    Commented May 10, 2011 at 4:40
  • 3
    no: "... this class does not inherently provide functionality for adding files to or extracting files from .zip archives."
    – user492238
    Commented May 10, 2011 at 4: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
    Commented May 10, 2011 at 4: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
    Commented May 11, 2011 at 4:18

4 Answers 4

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.

1
  • 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. Commented Jun 3, 2014 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.

1
  • 2
    OP asked for .NET 4.0
    – dlchambers
    Commented Mar 3, 2017 at 20:20
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.

2
  • 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
    Commented May 11, 2011 at 4: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. Commented May 12, 2011 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

1
  • 2
    OP question was about .NET 4.0 Commented Mar 31, 2017 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.