Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core

New to Telerik Document Processing? Download free 30-day trial

Getting Started

RadZipLibrary allows you to load data from existing ZIP archives or create and edit ZIPs that can be used by other applications. You can also create ZIP archives in memory or use a stream to get data and add it to a ZIP archive.

If you still don't have Telerik Document Processing installed, check the First Steps topic to learn how you can obtain the packages through the different suites.

The ZIP archive is represented by ZipArchive class. It can be used in 3 modes:

  • Read: Allows reading of the existing ZIP archive. In this mode it is not possible to add or update archive entries.

  • Create: Allows creation of a new archive. In this mode you can add new entries in the archive but cannot read or update content of the entries which have been written already.

  • Update: Allows update of the existing ZIP archive. In this mode you can add new entries, read and update existing entries.

Assembly References

The libraries support .NET 4 and later. .NET Standard-compatible binaries are available as well. The assemblies for .NET Standard don't include 'Windows' in their names. (e.g. Telerik.Zip.dll).

.NET Framework .NET Standard-compatible
Telerik.Windows.Zip.dll Telerik.Zip.dll

The binaries compatible with .NET Standard are distributed with the packages targeting .NET Standard and .NET Core. You can obtain the assemblies through the UI for ASP.NET Core, UI for Blazor and UI for Xamarin suites. There are NuGet packages as well that you can access if you have a license for one of the above mentioned suites.

Open Zip Archive

The code snippet from Example 1 demonstrates how to open existing Zip archive using the ZipArchive class.

Example 1: Open archive

using (Stream stream = File.Open("test.zip", FileMode.Open)) 
    using (ZipArchive archive = new ZipArchive(stream)) 
        // Display the list of the files in the selected zip file using the ZipArchive.Entries property. 
Using stream As Stream = File.Open("test.zip", FileMode.Open) 
    Using archive As New ZipArchive(stream) 
        ' Display the list of the files in the selected zip file using the ZipArchive.Entries property. 
    End Using 
End Using 

The archive variable holds the files that are compressed in the selected zip. You can access the list of these files through the ZipArchive.Entries property. It holds a collection of ZipArchiveEntry elements - the elements that describe the files archived in the zip file. You can use these elements to get the name of the compressed file, its uncompressed and compressed size and other file attributes.

Create Zip Archive

Example 2 shows how to create a new Zip archive using the ZipArchive class and place a text file in it.

Example 2: Create archive

using (Stream stream = File.Open("test.zip", FileMode.Create)) 
    using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, false, null)) 
        using (ZipArchiveEntry entry = archive.CreateEntry("text.txt")) 
            StreamWriter writer = new StreamWriter(entry.Open()); 
            writer.WriteLine("Hello world!"); 
Using stream As Stream = File.Open("test.zip", FileMode.Create) 
    Using archive As New ZipArchive(stream, ZipArchiveMode.Create, False, Nothing) 
        Using entry As ZipArchiveEntry = archive.CreateEntry("text.txt") 
            Dim writer As New StreamWriter(entry.Open()) 
            writer.WriteLine("Hello world!") 
        End Using 
    End Using 
End Using 

If you use StreamWriter to write content to the stream, you should call the Flush() method in order to flush the data to the stream.

Do not close the stream opened by the ZipArchiveEntry.Open() method. Otherwise the result is unpredictable.

See Also

In this article
Not finding the help you need? Improve this article