Compressing and Decompressing Folders in C#
Asked Answered
H

5

5

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.

Herbertherbicide answered 20/1, 2011 at 14:37 Comment(0)
S
2

GZip only ever deals with single files, which is why under *nix you end up having to archive them into a TAR file first which is then compressed.

If you want multiple files/folders you'll need a format which supports it, like ZIP.

You might want to thus look at: http://www.sharpdevelop.net/OpenSource/SharpZipLib/

Slipnoose answered 20/1, 2011 at 14:47 Comment(0)
E
8

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.

Elyn answered 20/1, 2011 at 14:40 Comment(0)
C
3

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

System.IO.Compression.ZipArchive Class

Catalog answered 24/4, 2013 at 14:34 Comment(0)
S
2

GZip only ever deals with single files, which is why under *nix you end up having to archive them into a TAR file first which is then compressed.

If you want multiple files/folders you'll need a format which supports it, like ZIP.

You might want to thus look at: http://www.sharpdevelop.net/OpenSource/SharpZipLib/

Slipnoose answered 20/1, 2011 at 14:47 Comment(0)
W
1

You could take a look at this library instead.

Wald answered 20/1, 2011 at 14:39 Comment(0)
P
0

Take a look at DotNetZip Lib.

Projective answered 20/1, 2011 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.