Hi nauna,
Check this sample. now take its reference and correct your code.
I have created this sample using this link.
HTML
<asp:Button ID="btnDownload" Text="Download All File" runat="server" OnClick="OnDownload" />
Namespaces
C#
using Ionic.Zip;
VB.Net
Imports Ionic.Zip
Code
C#
protected void OnDownload(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("Files");
string lbl3dfiles = Server.MapPath("~/Files/Test.doc");
string lblstl = Server.MapPath("~/Files/Test.pdf");
string lblgcode = Server.MapPath("~/Files/Test.txt");
string lblprintcoder = Server.MapPath("~/Files/Test.xls");
if (lbl3dfiles != string.Empty)
{
zip.AddFile(lbl3dfiles, "Files");
}
if (lblstl != string.Empty)
{
zip.AddFile(lblstl, "Files");
}
if (lblgcode != string.Empty)
{
zip.AddFile(lblgcode, "Files");
}
if (lblprintcoder != string.Empty)
{
zip.AddFile(lblprintcoder,"Files");
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("dd-MMM-yyyy-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
Response.End();
}
}
VB.Net
Protected Sub OnDownload(sender As Object, e As System.EventArgs) Handles btnDownload.Click
Using zip As ZipFile = New ZipFile()
zip.AlternateEncodingUsage = ZipOption.AsNecessary
zip.AddDirectoryByName("Files")
Dim lbl3dfiles As String = Server.MapPath("~/Files/Test.doc")
Dim lblstl As String = Server.MapPath("~/Files/Test.pdf")
Dim lblgcode As String = Server.MapPath("~/Files/Test.txt")
Dim lblprintcoder As String = Server.MapPath("~/Files/Test.xls")
If lbl3dfiles <> String.Empty Then
zip.AddFile(lbl3dfiles, "Files")
End If
If lblstl <> String.Empty Then
zip.AddFile(lblstl, "Files")
End If
If lblgcode <> String.Empty Then
zip.AddFile(lblgcode, "Files")
End If
If lblprintcoder <> String.Empty Then
zip.AddFile(lblprintcoder, "Files")
End If
Response.Clear()
Response.BufferOutput = False
Dim zipName As String = String.Format("Zip_{0}.zip", DateTime.Now.ToString("dd-MMM-yyyy-HHmmss"))
Response.ContentType = "application/zip"
Response.AddHeader("content-disposition", "attachment; filename=" & zipName)
zip.Save(Response.OutputStream)
Response.[End]()
End Using
End Sub
Screenshot