Create A Zip File Using ASP.NET And C#

Introduction
 
In this article I will explain how to create a zip file using ASP.NET & C#. In this purpose we can use Ionic.Zip.dll reference for creating Zip file in ASP.NET. So first we download the dll through this link Ionic.Zip.dll.
 
Assemblies Required
 
After downloading the Ionic.Zip.dll Zip file you can get many folders inside the zip file. Go to zip-v1.9-Reduced folder Inside the zip file, then open the particular folder that contain Ionic.Zip.Reduced.dll.
 
We must add the following namespace:
  1. using Ionic.Zip;  
Code
 
The following code will create zip file in ASP.NET with the help of  Ionic.Zip.Reduced.dll.
  1. protected void btn_zip_Click(object sender, EventArgs e)  
  2. {  
  3.     string path = Server.MapPath("~/Test/");//Location for inside Test Folder  
  4.     string[] Filenames = Directory.GetFiles(path);  
  5.     using (ZipFile zip = new ZipFile())  
  6.     {  
  7.         zip.AddFiles(Filenames, "Project");//Zip file inside filename  
  8.         zip.Save(@"C:\Users\user\Desktop\Projectzip.zip");//location and name for creating zip file  
  9.            
  10.     }  
  11. }  
  • Code line number 03 describe the location of the file. Those files we can convert into zip format.
  • Code line number 07 describe that the particular name of the file inside the zip file.
  • Code line number 08 define the name of the zip file we are going to create.
Dll Reference
 
Add the Downloaded dll inside the Bin Folder. 
 
 
Design
 
 
 
Output
 
Created the Zip file. 
 
 
 
Inside The Zip File.
 
 
Reference
Summary
 
We learned how to create a Zip file using ASP.NET and C#. I hope this article is useful for all .NET beginners. 


Similar Articles