Unzip a MemoryStream (containing the zip file) and get the files

Yes, .Net 4.5 now supports more Zip functionality.

Here is a code example based on your description.

In your project, right click on the References folder and add a reference to System.IO.Compression

using System.IO.Compression;

Stream data = new MemoryStream(); // The original data
Stream unzippedEntryStream; // Unzipped data from a file in the archive

ZipArchive archive = new ZipArchive(data);
foreach (ZipArchiveEntry entry in archive.Entries)
{
    if(entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
    {
         unzippedEntryStream = entry.Open(); // .Open will return a stream
         // Process entry data here
    }
}

Hope this helps.

Leave a Comment