Edit this page
Available for: UI for ASP.NET AJAX | UI for ASP.NET MVC | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin

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.

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.

In order to use RadZipLibrary in your application, you need to add a reference to the Telerik.Windows.Zip assembly.

Open Zip Archive

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

[C#] 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.
    }
}

[VB.NET] Example 1: Open archive

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.

[C#] 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!");
            writer.Flush();
        }
    }
}

[VB.NET] Example 2: Create archive

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!")
            writer.Flush()
        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