It's an online zip opener. It's handy in the cases when you are asked to download a zip file, but you really don't feel like filling up your desktop with yet another zip when all you need is a single file for the content. Or perhaps for the cases where you'd like to link directly to a file within a zip. Or for when you want to index a zip file (as always I think in search) :-)
It's basically a web app, that takes two parameters: "zip" with a url to the zip file you want to examine and "file" for the file name/path within that zipfile that you want to extract.
In case you only give the "zip" parameter it will list the content of the zip file.
The most important method is this (and yes, I realize the code isn't pretty - it's just a simple poc):
protected void LoadZip(string url, string file)
Error.Text = "";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (resp.ContentType == "application/x-zip-compressed")
if (resp.ContentLength < 2000000)
BinaryReader br = new BinaryReader(resp.GetResponseStream());
byte buf = br.ReadBytes((int)resp.ContentLength);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);
ZipFile zf = new ICSharpCode.SharpZipLib.Zip.ZipFile(ms);
if (file != null)
ZipEntry ze = zf.GetEntry(file);
Stream filestream = zf.GetInputStream(ze);
BinaryReader br2 = new BinaryReader(filestream);
byte newbuf = br2.ReadBytes((int)ze.Size);
Response.ContentType = MimeType(file);
BinaryWriter bw2 = new BinaryWriter(Response.OutputStream);
GridView1.DataSource = zf;
Error.Text = "Zip file too big";
Error.Text = "Wrong content type: " + resp.ContentType;
A couple of parts was a bit tricky. First the part that loads the external zip into a memorystream for easy access by the sharpziplib. It turns out that the BinaryReader was quite necessary in order to load it without corrupting the data. Also determining which mimetype a given document in the zip file is, before sending it out wasn't all that easy, but in the end I found a solution online. This solution looks up mimetypes in the registry so it does require registry access for the aspnet user - that can potentially be a problem.
There's several known problems with this implementation, but I'll leave it to you guys to figure them out :-)
Download the code here.
Try it here (note that my "playground" server where this is on might be closed down pretty soon - enjoy while you can).