In this article, I will show you how to download multiple files and download as zip file using c# .net.
To achieve zip features I used third party libraries DotNetZip. It was supported by .NET 4.5 and used for zip file manipulation such as adding ,extracting files, etc.
Here I Bind the CheckboxList with the list of files from the server folder path using directory.Getfiles on pageLoad and has a download button. The checkboxList allows the user to select the files as they wish and download it.
<form id="form1" runat="server">
<div style="border: 1px solid #357ae8; padding:15px 15px 15px 15px ; width: 400px; height: 250px">
<asp:CheckBoxList ID="chkAlbum" runat="server">
<asp:Button ID="btnDownload" runat="server" OnClick="btnDownload_Click" Text="Download as zip file" />
Code Behind Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
string files = Directory.GetFiles(Server.MapPath(".") + @"\Uploads");
foreach (string file in files)
chkAlbum.Items.Add(new ListItem(Path.GetFileName(file), file));
protected void btnDownload_Click(object sender, EventArgs e)
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + "Donload.zip");
using (ZipFile zip = new ZipFile())
foreach (ListItem item in chkAlbum.Items)
Post your comments / questions
- How to check PAN-Aadhaar is Linked or NOT?
- How to customize pagination for django admin?
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED