Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 13, 2009 01:55 PM by Svante
Nov 17, 2005 03:54 AM|LINK
Can anyone tell me if there is any inbuilt utility in windows shell API with the help of which we can Unzip the files. I need to use that and Unzip the files using c# code.
Nov 17, 2005 02:07 PM|LINK
To my knowledge there isn't anything in the .net framework, but it's a great idea, trying to get at something in the windows framework. I havne't seen anyone do it, but I know there are a couple of open source routines using the zip/gzip libraries.
I'm using the nSoftware zip library, which is extremely easy to use. Literally a few ( <10 ) lines of code to write top open, create, add, or modify zip files. Password protectio and everything is there.
Not sure of your situation, but This is a case where I'd lean towards something that is already proven, and not re-invent the wheel.
Nov 17, 2005 08:19 PM|LINK
Nov 18, 2005 03:45 PM|LINK
Jan 31, 2009 10:46 AM|LINK
Following is an example of decompressing a file having bytes in memory stream using sharpziplib.
ZipEntry entry = compressedBytes.GetNextEntry();
bytesRead = compressedBytes.Read(tempBuffer, 0, tempBuffer.Length);
tempMemoryStream.Write(tempBuffer, 0, bytesRead);
Jan 31, 2009 11:53 AM|LINK
windows shell API
Do you *really* mean that? Why do you need it to be in the windows shell API?
need to use that and Unzip the files using c# code.
Feb 12, 2009 10:59 PM|LINK
No, you cannot use those classes for processing ZIP files, at least not easily. System.IO.Compression does DeflateStream and GZipStream, which will neither read nor write a ZIP file. System.IO.Packaging will do ZIP files, but it is unwieldy for that purpose.
A complex interface and probably not what you want. This gap is why there are 3rd party libraries to do ZIP files in .NET.
SharpZipLib has been around a long time, but the interface is sort of clunky and error prone. To give you an example of what I mean, here is the "Extract into a memory stream" code for DotNetZip, that is equivalent to the post from above:
MemoryStream ms = new MemoryStream();
using (ZipFile zip = ZipFile.Read(ZipFileToRead))
That assumes ZipFileToRead is the name of a zipfile on disk that you can read. If you have the ZipFile data in a MemoryStream, and you want to extract an entry into a different MemoryStream, you can do that, too. Just replace ZipFileToRead in the above
with a readable Stream. Easy.
It's also easy to create a zip with DotNetZip and save it to Response.OutputStream, or to any disk file in a writable directory.
DotNetZip is available at http://www.codeplex.com/DotNetZip
ZIP on Server
Feb 13, 2009 07:19 AM|LINK
No, you cannot use those classes for processing ZIP files, at least not easily.
Sadly, you're quite right. Not easily, more code is required.
There is yet another option though, and that's to use the J# library implementation:
http://msdn.microsoft.com/en-us/magazine/cc164129.aspx . I have not done so personally, but it does seem a viable alternative.
System.IO.Packaging will do ZIP files, but it is unwieldy for that purpose.
Yes, once again you're right, sadly enough. Unwieldy indeed.
Feb 13, 2009 07:36 AM|LINK
public string ZipFile(string savePath,
string sFlag = "Error";
FileOutputStream fileOutput = new FileOutputStream(savePath);
ZipOutputStream zipOutput = new ZipOutputStream(fileOutput);
FileInputStream fileInput = null;
foreach (string file
fileInput = new FileInputStream(file);
ZipEntry zipEntry = new ZipEntry(Path.GetFileName(file));
sbyte buffer = new sbyte;
int len = 0;
while ((len = fileInput.read(buffer)) >= 0)
zipOutput.write(buffer, 0, len);
return sFlag = "Success";
private List<ZipEntry> GetZipFiles(ZipFile zipfill)
List listZip = new List();
Enumeration zipEnum = zipfill.entries();
ZipEntry zipEntry = (ZipEntry)zipEnum.nextElement();
public string UnZipFile(string zippedFile,
string sFlag = "Error";
ZipFile zipfile = new ZipFile(zippedFile);
List zipFiles = GetZipFiles(zipfile);
foreach (ZipEntry zipFile
InputStream s = zipfile.getInputStream(zipFile);
Directory.CreateDirectory(destPath + "\\" + Path.GetDirectoryName(zipFile.getName()));
FileOutputStream dest = new FileOutputStream(Path.Combine(destPath +
"\\" + Path.GetDirectoryName(zipFile.getName()), Path.GetFileName(zipFile.getName())));
int len = 0;
sbyte buffer =
while ((len = s.read(buffer)) >= 0)
dest.write(buffer, 0, len);
sFlag = "Success";
Feb 13, 2009 01:43 PM|LINK
Yes, the J# runtime can be used to process zip files.
I had a few problems with it, myself: First, the API. It's a complex API for handling basic zip functions. Look at all the code you have to write to zip and unzip. Also the feel of the API is very un-.NET - no generics, no .NET enumeration, no indexers,
no properties, no progress events, etc. All the fundamental .NET stuff is missing from the J# library, because it is based in Java and oriented to that language (c.1998, not the recent versions). This means that J# is not very friendly when being integrated
into other frameworks, like LINQ, ASP.NET (eg Data bound controls) or even Windows Forms.
Second, it drags in the J# runtime, which is huge, just huge. You can't just get the zip stuff, you have to take everything. And also, now J# is reaching end of support.
http://msdn.microsoft.com/en-us/vjsharp/default.aspx . It looks like mainstream support for the runtime will end in 2010, not long off now.
Third, the features of the java.util.zip library are limited and there is no chance of expansion for .NET languages. Poor encryption; no support for zip64, self-extracting archives, or Unicode; and so on.
Given all that, third-party libraries like DotNetZip and SharpZipLib evolved to fill the gap.