How to extract a folder from a zip file using SharpZipLib?

I have a test.zip file that contains a folder inside with a bunch of other files and folders in it.

I discovered SharpZipLib after finding out that .gz / GzipStream was not the same as using it for individual files. More importantly, this is similar to using GZipStream , which means it will create a FILE. But I have a whole folder. How do I unzip

For some reason, the unboxing example here is set to ignore directories, so I'm not quite sure how to do this.

Also, I need to use .NET 2.0 to accomplish this.

+7
c # folder zip decompression
source share
3 answers

I think this is an easier way. Default functionality (please see here for more information https://github.com/icsharpcode/SharpZipLib/wiki/FastZip )

extract it using folders.

the code:

 using System; using ICSharpCode.SharpZipLib.Zip; var zipFileName = @"T:\Temp\Libs\SharpZipLib_0860_Bin.zip"; var targetDir = @"T:\Temp\Libs\unpack"; FastZip fastZip = new FastZip(); string fileFilter = null; // Will always overwrite if target filenames already exist fastZip.ExtractZip(zipFileName, targetDir, fileFilter); 
+17
source share

This link explains exactly what you need to achieve:

http://community.sharpdevelop.net/forums/p/6873/23543.aspx

+2
source share

Here is how I did it:

 public void UnZipp(string srcDirPath, string destDirPath) { ZipInputStream zipIn = null; FileStream streamWriter = null; try { Directory.CreateDirectory(Path.GetDirectoryName(destDirPath)); zipIn = new ZipInputStream(File.OpenRead(srcDirPath)); ZipEntry entry; while ((entry = zipIn.GetNextEntry()) != null) { string dirPath = Path.GetDirectoryName(destDirPath + entry.Name); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } if (!entry.IsDirectory) { streamWriter = File.Create(destDirPath + entry.Name); int size = 2048; byte[] buffer = new byte[size]; while ((size = zipIn.Read(buffer, 0, buffer.Length)) > 0) { streamWriter.Write(buffer, 0, size); } } streamWriter.Close(); } } catch (System.Threading.ThreadAbortException lException) { // do nothing } catch (Exception ex) { throw (ex); } finally { if (zipIn != null) { zipIn.Close(); } if (streamWriter != null) { streamWriter.Close(); } } } 

This is messy, but I hope this helps!

0
source share

All Articles