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:
Code
The following code will create zip file in ASP.NET with the help of Ionic.Zip.Reduced.dll.
- protected void btn_zip_Click(object sender, EventArgs e)
- {
- string path = Server.MapPath("~/Test/");
- string[] Filenames = Directory.GetFiles(path);
- using (ZipFile zip = new ZipFile())
- {
- zip.AddFiles(Filenames, "Project");
- zip.Save(@"C:\Users\user\Desktop\Projectzip.zip");
-
- }
- }
- 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.