Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use System.IO.Compression to read/write ZIP files?

Tags:

I know there are libraries out there for working with ZIP files. And, you can alternatively use the functionality built into Windows for working ZIP files.

But, I'm wondering if anyone has worked out how to use the tools built into the System.IO.Compression namespace within .NET for reading/writing ZIP files? Or, is it not possible using only this namespace?

UPDATED: I've seem someone comment that the System.IO.Packaging namespace might be usefull with this also. Does anyone know exactly how to do it?

like image 766
Chris Pietschmann Avatar asked Oct 08 '08 18:10

Chris Pietschmann


People also ask

What is System IO compression ZipFile?

ZipFile.Open Method (System.IO.Compression)Opens a zip archive at the specified path and in the specified mode.

What is the difference between ZIP and GZIP?

The most important difference is that gzip is only capable to compress a single file while zip compresses multiple files one by one and archives them into one single file afterwards. Thus, gzip comes along with tar most of the time (there are other possibilities, though). This comes along with some (dis)advantages.

How does a compressed ZIP folder work?

Folders that are compressed using the Compressed (zipped) Folders feature use less drive space and can be transferred to other computers more quickly. You can work with a compressed folder and the files or programs it contains just as you would an uncompressed folder.


2 Answers

MSDN has a complete example http://msdn.microsoft.com/en-us/library/system.io.packaging.zippackage.aspx using the ZipPackage class. Requires .NET 3.5.

like image 145
Dave Moore Avatar answered Sep 21 '22 08:09

Dave Moore


Dave, very nice!! I didn't know that was in there.

Now that I know what to look for, I was able to find an article with a small code sample on how to use it: http://weblogs.asp.net/jgalloway/archive/2007/10/25/creating-zip-archives-in-net-without-an-external-library-like-sharpziplib.aspx

On a related note, I also found the DotNetZip project that looks extremely easy to use.

like image 28
Chris Pietschmann Avatar answered Sep 19 '22 08:09

Chris Pietschmann