Xceed .NET Libraries Documentation
Listing the contents of a zip file

Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Zip and streaming capabilities > Listing the contents of a zip file

This topic demonstrates how to get a listing of all of the files contained in a zip file.

Basic steps

To list the contents of a zip file, the following steps must be performed:

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

  • Call the GetFiles method to retrieve a listing of the files contained within the zip file. 

  • You can now loop through the files and extract the desired information.

Demonstration

This example demonstrates how to list the contents of a zip file.

VB.NET Copy Code

Imports Xceed.Zip
Imports Xceed.FileSystem

Dim zip As New ZipArchive(New DiskFile("c:\test.zip"))
Dim f As AbstractFile

For Each f In zip.GetFiles( True )
   ListBox1.Items.Add( f.FullName )
Next

C# Copy Code
using Xceed.Zip;
using Xceed.FileSystem;
 
ZipArchive zip = new ZipArchive( new DiskFile( @"c:\test.zip" ) );
 
foreach( AbstractFile f in zip.GetFiles( true ) )
{
   Console.WriteLine( f.FullName );

Things you should consider

The main questions you should ask yourself when listing the contents of a zip file are:

  • Do you want to filter (specify specific files and folders) the items that are to be listed? Use filters

  • Do you also want to retrieve a listing of the zipped folders? Use the GetFolders method. 

  • Do you want to retrieve a reference to a single zipped file or folder? Use the GetFile or GetFolder methods. 

  • Do you want to display the status of the operation? See the Events topic. 

  • Do you want to list the contents of a specific folder within the zip file? Create an instance of a ZippedFolder object rather than a ZipArchive object.    

  • Do you want to filter your list of items? See the Filters topic.     

  • Do you only want to do basic zip file operations? Use the QuickZip class.