How to read data from a zip file without having to unzip the entire file

AwkwardCoder picture AwkwardCoder · May 11, 2011 · Viewed 130.5k times · Source

Is there anyway in .Net (C#) to extract data from a zip file without decompressing the complete file?

Simply I possibly want to extract data (file) from the start of a zip file, obviously this depends if the compression algorithm compress the file in a deterministic order.

Answer

Sinatr picture Sinatr · Feb 7, 2013

With .Net Framework 4.5 (using ZipArchive):

using (ZipArchive zip = ZipFile.Open(zipfile, ZipArchiveMode.Read))
    foreach (ZipArchiveEntry entry in zip.Entries)
        if(entry.Name == "myfile")
            entry.ExtractToFile("myfile");

Find "myfile" in zipfile and extract it.