<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Create ZIP Files in Asp.net using c#,vb.net</title>
</head>
<body>
<form id="form1"
runat="server">
<div>
<asp:FileUpload ID="fileUpload1"
runat="server"
/>
<asp:Button ID="btnUpload"
runat="server"
Text="Upload
Files" onclick="btnUpload_Click" />
<asp:Button ID="btnZip"
Text="Create Zip
Files" runat="server" onclick="btnZip_Click" />
<asp:Label ID="lbltxt"
runat="server"
Font-Bold="true"
ForeColor="Red"
/>
</div>
</form>
</body>
</html>
using System;
using System.IO;
using Ionic.Zip;
protected void
btnUpload_Click(object sender, EventArgs e)
{
if(fileUpload1.HasFile)
{
string filename = Path.GetFileName(fileUpload1.PostedFile.FileName);
string path = Server.MapPath("~/SampleFiles/" + filename);
fileUpload1.SaveAs(path);
lbltxt.Text = "File
Uploaded Successfully";
}
}
// Zip all files from folder
protected void
btnZip_Click(object sender, EventArgs e)
{
string path = Server.MapPath("~/SampleFiles/");
string[] filenames = Directory.GetFiles(path);
using (ZipFile
zip = new ZipFile())
{
zip.AddFiles(filenames,"files");
zip.Save(Server.MapPath("~/samplefiles.zip"));
lbltxt.Text = "ZIP
File Created Successfully";
}
}