This project is read-only.

Extract in Memory and download a single file

Oct 18, 2010 at 8:27 PM

I have a file on our webserver created with  AES encryption and would like to extract one file from it to download. I don't know it is possible to not.

Using zip As new ZipFile(FilePath)
    Dim e As ZipEntry
    For Each e In zip
        If (e.UsesEncryption)
        End If
End Using

I appreciate if any one can help.




Oct 18, 2010 at 10:16 PM

The sample code that you show, should work to extract all entries from the zipfile into the filesystem.

It sounds to me like you would like to extract a single entry, and you want to do it from code that runs within ASPNET.  You then want to download the contents of that entry to the requesting browser.

You first need to select one particular entry.  You can do this with ZipFile.SelectEntries, or with the string-based indexer on the ZipFile class.  (eg, zip("EntryName") ).  Then you need to appropriately extract the contents of that entry.  You can do this with one of the ZipEntry.Extract overloads that accepts a stream for output, passing in the Response.OutputStream.  You can also do it by calling ZipEntry.OpenReader(), manually reading the data, and then writing it to Response.OutputStream (this is sometimes called a "data pump", a common technique in streams-based IO handling).   In either case you will have to employ the logic that tests UsesEncryption, and call the overload with the appropriate password.

Good luck.


Oct 19, 2010 at 12:15 PM
Edited Oct 19, 2010 at 12:16 PM

Hi Cheeso,

I am using windows form (VB.NET). I am trying to download a file from our web server. The zip file contain only one single file. I want to extract it in the memory and then download the actual file from the zip instead of a zipfile itself and as I said before that it is a password protected.


Oct 24, 2010 at 2:47 PM
Edited Oct 24, 2010 at 3:15 PM

ok, no problem.

Start with the code you have above.  Modify it to eliminate the FOR loop.  You want to extract a single entry, not all of them.  So eliminate the loop.  Select the entry by name or number, using the indexer on the ZipFile class.  Then call .ExtractWithPassword() on that ZipEntry, and specify the Response.OutputStream for the output stream. 

There are examples in the DotNetZip source that show how to do this.

I thought there were examples that did this, but apparently that's not true. Even so, it shouldn't be difficult.