ZipLibrary - Read Data from Zip File

You can select only one ZIP file at a time and upload it on the server.

Demo Configurator

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

By pressing the "Show zipped files' details in RadGrid" button the data from the zip file will be read and the details will be shown in Telerik’s ASP.NET Grid control. If you select the “Keep the info about my uploaded items upon a next upload” checkbox, the data about your previously uploaded items will be preserved upon a consecutive upload.

The example demonstrates how to read all the data from a ZIP file simultaneously and display the information about the compressed files in Telerik’s ASP.NET Grid - name, original and compressed size. In order to load data from uploaded ZIP files, you can take advantage of the ZipArchive and ZipArchiveEntry classes and their methods. For example:

        UploadedFile file = AsyncUpload1.UploadedFiles[0];
        using (ZipArchive archive = new ZipArchive(file.InputStream))
            List<ZipArchiveEntry> allEntries = archive.Entries.ToList();
            foreach (ZipArchiveEntry entry in allEntries)
                FileHelper fileHelper = new FileHelper();
                fileHelper.CompressedSize = entry.CompressedLength;
                fileHelper.UncompressedSize = entry.Length;
                fileHelper.FileNameInZip = entry.Name;
                byte[] data = new byte[entry.Length];
                Stream entryStream = entry.Open();
                BinaryReader reader = new BinaryReader(entryStream);
                reader.Read(data, 0, data.Length);
                fileHelper.Data = data;
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
    • DefaultCS.aspx.cs
    • FileHelper.cs
  • scripts.js
  • styles.css
<%@ Page Title="" Language="C#"  AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="ZipLibrary_Examples_ReadDataFromZipFile_DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns=''>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
    <script src="scripts.js" type="text/javascript"></script>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <qsf:MessageBox ID="InformationBox1" Icon="Info" Type="Info" runat="server">
            You can select only one ZIP file at a time and upload it on the server.
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="conditionalPostback">
            <telerik:AjaxSetting AjaxControlID="Panel1">
                    <telerik:AjaxUpdatedControl ControlID="Panel1" />
            <telerik:AjaxSetting AjaxControlID="CheckBox1">
                    <telerik:AjaxUpdatedControl ControlID="CheckBox1" />
                    <telerik:AjaxUpdatedControl ControlID="Panel1" />
    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1"></telerik:RadAjaxLoadingPanel>
    <asp:Panel runat="server" ID="Panel1" CssClass="demo-container size-wide">
            runat="server" ID="AsyncUpload1" MaxFileInputsCount="1" AllowedFileExtensions="zip" />
        <br />
        <br />
        <telerik:RadButton RenderMode="Lightweight" Text="Show zipped files' details in RadGrid" ID="Button1" OnClick="Button1_Click" runat="server"></telerik:RadButton>
        <br />
        <br />
        <telerik:RadGrid RenderMode="Lightweight" OnItemCommand="RadGrid1_ItemCommand" runat="server" ID="RadGrid1"
            PageSize="10" AllowSorting="true" AutoGenerateColumns="false"
            AllowPaging="true" OnNeedDataSource="RadGrid1_NeedDataSource">
            <MasterTableView DataKeyNames="ID">
                    <telerik:GridTemplateColumn UniqueName="FileExtensionIconColumn">
                        <HeaderStyle Width="20px" />
                            <asp:Image runat="server" ImageUrl='<%# Eval("IconPath") %>' />
                    <telerik:GridBoundColumn DataField="FileNameInZip" HeaderText="File Name"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CompressedSize" HeaderText="Compressed Size"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UncompressedSize" HeaderText="Uncompressed Size"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="DownloadTemplateColumn">
                        <HeaderStyle Width="40px" />
                            <telerik:RadButton RenderMode="Lightweight" runat="server" ID="RadButton1" CommandName="Custom" Text="Download file"></telerik:RadButton>

    <qsf:ConfiguratorPanel ID="ConfiguratorPanel1" runat="server" Title="Demo Configurator">
                <ul class="fb-group">
                        <span class="checkbox">
                            <asp:CheckBox ID="CheckBox1" AutoPostBack="true" runat="server" Text="Keep the info about my uploaded items upon a next upload" /></span>

Support & Learning Resources

Find Assistance

Help Us Improve

Was this example helpful?