Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing and Decompressing Folders in C#

I want to compress and decompress a folder using C#. The problem with GZipStream is that it takes filenames and hence I need to write a recursive logic.

Can I somehow do it like, give source folder name and destination filename to compress the complete folder with hierarchy. I need to do vice-versa for de-compressing the folder as well. If its not possible through C#/.net directly please suggest some Free 3rd party.

like image 539
Saubhagya Avatar asked Jan 20 '11 14:01

Saubhagya


2 Answers

I've used the free SharpZipLib multiple times and I'd recommend that you take a look at it. It's quite easy to use and have worked well for all my use cases.

like image 140
Hans Olsson Avatar answered Oct 03 '22 19:10

Hans Olsson


Now included in .NET 4.5 if you'd rather stay off non microsoft libs.

System.IO.Compression.ZipArchive Class

like image 31
Crypth Avatar answered Oct 03 '22 18:10

Crypth