Xceed .NET Libraries Documentation
Extracting items to memory (unzipping)

Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Zip and streaming capabilities > Unzipping > Extracting items to memory (unzipping)

This topic demonstrates how to extract files and folders from a zip file to a folder located in memory. With Xceed Zip for .NET, a folder is a folder; it does not matter if it is located within a zip file, on disk or in memory. 

When unzipping the contents of a spanned zip file, the last disk must be in the drive before the operation begins (when the instance of the ZipArchive class has been created).

Basic steps

To extract items from a zip file to memory, the following steps must be performed:

  • Retrieve a reference to a new or existing zip file using the ZipArchive class. 

  • Retrieve a reference to a new or existing folder using the MemoryFolder class. This is the location to which the files contained within the zip file will be extracted to. 

  • Call the CopyFilesTo method to copy the entire contents of the zip to the destination folder.

Demonstration

This example demonstrates how to unzip files from a zip file to a folder located in memory.

VB.NET Copy Code

Imports Xceed.Zip
Imports Xceed.FileSystem 

Dim zip As New ZipArchive( new DiskFile( "d:\test.zip" ) ) 

Dim folder As New MemoryFolder( "RAM_Drive", "folder" ) 

zip.CopyFilesTo( folder, true, true )

C# Copy Code

using Xceed.Zip;
using Xceed.FileSystem;

ZipArchive zip = new ZipArchive( new DiskFile( @"d:\test.zip" ) ); 

MemoryFolder folder = new MemoryFolder( "RAM_Drive", "folder" ); 

zip.CopyFilesTo( folder, true, true );

Things you should consider

The main questions you should ask yourself when extracting items from a zip file are: