In this article I will explain how to Upload, Unzip and Extract contents Zip Archive file in ASP.Net using C# and VB.Net. In order to Unzip and Extract contents of Zip Archive file in ASP.Net I am making use of DotNetZipLibrary which is a free Open Source Library for .Net.
The files are extracted in a folder on server and then displayed in GridView.
You might also like to read:
Referencing the DotNetZip Library
You will need to download the DotNetZip Library DLL using the Download Link provided below.
Download DotNetZip Or your will find the DLL in the attached sample at the end of the article.
Once you have the DLL you need to place the Ionic.Zip.Reduced.dll in the BIN Folder.
You will need to import the following Namespaces
The HTML Markup consists of an ASP.Net FileUpload control, a Button and a GridView control.
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="Upload" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="#3AC0F2"
<asp:BoundField DataField="FileName" HeaderText="File Name" />
<asp:BoundField DataField="CompressedSize" HeaderText="Compressed Size (Bytes)" />
<asp:BoundField DataField="UncompressedSize" HeaderText="Uncompressed Size (Bytes)" />
Upload, Unzip and Extract contents of Zip Archive File in ASP.Net
Once the Zip file is uploaded it is read using the DotNetZip ZipFile Read method to which I have passed the InputStream object of the FileUpload PostedFile property.
Then the Zip File is extracted to the folder. The Extract All method has an additional parameter ExtractExistingFileAction, for which I have specified DoNotOverwrite so that if a file with same name exists, it will not be overwritten.
protected void Upload(object sender, EventArgs e)
string extractPath = Server.MapPath("~/Files/");
using (ZipFile zip = ZipFile.Read(FileUpload1.PostedFile.InputStream))
GridView1.DataSource = zip.Entries;
Protected Sub Upload(sender As Object, e As EventArgs)
Dim extractPath As String = Server.MapPath("~/Files/")
Using zip As ZipFile = ZipFile.Read(FileUpload1.PostedFile.InputStream)
GridView1.DataSource = zip.Entries
Note: If you want to learn how to download files from folder. Please refer