Naveen's Weblog

Bridge to future

Zip/Unzip using System.IO.Package in .Net

Posted by codingsense on December 5, 2010


I was working on a project where it was required to zip and unzip files, these days we were using Cabarc.exe and all was working fine. Now we planned to give unicode support and booom!! cabarc.exe failed to zip the folder, since it does not support unicode characters. I found that there are many open source projects like SharpZipLib, DotNetZip etc. But we did not wanted to use the available open source projects to implement it. So I decided to search for some other option and what I found is System.IO.Package in WindowsBase.dll. It exposes a class called Package which will help to pack and unpack files and folders.

Download Source code (13 Kb)

I have made a separate dll (CustomPackage.dll) that you can use for zipping and unzipping of folders. I have also created a dummy project PackageWrapper to help you understand how to make calls to the dll.

Features:

  • The project supports Unicode characters in folder or files (Limitation with Cabarc.exe)
  • Zipping is done also for all sub directories . While unzipping the same directory structure will be maintained.

Improvements for you to do:
I have used Mime Type as MediaTypeNames.Application.Octet to make it generic and support all kind of files and have used the compression option CompressionOption.NotCompressed since the mime type will not compress. If you know that you will have only similar type of files to zip or unzip then you can select proper Mime type and compression option as CompressionOption.Maximum to compress the files to maximum extent.

For any kind of improvements or clarifications please feel free to comment.

Happy Coding 🙂
Codingsense

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: