This project is read-only.

Loading/displaying files without extracting them in C#?

Aug 20, 2009 at 10:00 AM

I was wondering if there's a way to display files from the zip without actually extracting them, for example, I click on a picture file in the list and it sets the picturebox control as the image I've selected in the zip.

Would I have to load this file into the memory or something? And how would I do this?


Aug 20, 2009 at 3:52 PM

Yes, you can enumerate the entries in a zipfile without extracting them.

using (var zip = ZipFile.Read(""))
    foreach (ZipEntry e in zip)
        // here you can do what you like with the entry.
        // you need not extract the entry.

To display the contents of the entry, you would need to read the zipentry content into memory, or extract the entry to create a filesystem file that contains the content.  If it's an image, you could just read in the data via a stream using ZipEntry.OpenReader().  Then, there are ways to create an image using the contents of a stream or byte array.  Depending on which framework you're targeting - WinForms, WPF, ASPNET - there are different ways to do this.  I'll let you figure that out.

That takes care of the image-type file.  For other file types (Word documents, text files, whatever) you'd have to do something similar I guess.

Aug 20, 2009 at 7:50 PM

Yay! Thank you so much! I'm going to mess around with that later tonight, oh and I'm using WinForms.

This information is extremely useful for what I'm making, thanks!