Hi,
I have uploaded 3 files using file upload with Specific User Id (Meaning User can have 3 image files or less than 3) in one folder
Now I want to download all 3 files at once by User Id (on page load or on button click event )
Is it possible ?
Thank You

Anoop Kumar SharmaRank #127 · 17.4K reputationPosted Jul 12, 2023, 11:07 PM EDT
Hi Sushant,
The best way is to zip all the multiple files and download the .zip file at the user end.
https://www.aspsnippets.com/Articles/Zip-a-Folder-Directory-and-Download-in-ASPNet-using-C-and-VBNet.aspx
Hope this will help you.
Mudzakkir TohaRank #3,303 · 435 reputationPosted Jul 12, 2023, 9:51 PM EDT
of course that is possible to do.
match your file using userId, or you can save file location to db with key userId. and then read the files using foreach.
Jignesh KumarRank #91 · 22.9K reputationPosted Jul 13, 2023, 12:25 AM EDT
Hello Sushant,
Please use this one which will help you out to download all files from specific folder,
using System; using System.IO; class Program { static void Main() { string sourceDirectory = @"C:\SourceFolder"; // Specify the source directory path string destinationDirectory = @"C:\DestinationFolder"; // Specify the destination directory path // Get all files within the source directory string[] files = Directory.GetFiles(sourceDirectory); // Copy each file to the destination directory foreach (string file in files) { string fileName = Path.GetFileName(file); string destinationPath = Path.Combine(destinationDirectory, fileName); File.Copy(file, destinationPath, true); } Console.WriteLine("Files downloaded successfully."); } }Praveen Mishra183 reputationPosted Jul 13, 2023, 4:38 AM EDT
Hi Sushant ,
You can easily download multiple files on pae load , here is the example code.
protected void Page_Load(object sender, EventArgs e) { string folderPath = Server.MapPath("~/Files"); // Path to the folder containing the files if (Directory.Exists(folderPath)) { string[] files = Directory.GetFiles(folderPath); foreach (string filePath in files) { string fileName = Path.GetFileName(filePath); string downloadUrl = "DownloadFile.aspx?file=" + Server.UrlEncode(fileName); Response.Write("" + fileName + " "); } } }Another Redirected Page Code of Page Load Are :
protected void Page_Load(object sender, EventArgs e) { string fileName = Request.QueryString["file"]; if (!string.IsNullOrEmpty(fileName)) { string filePath = Server.MapPath("~/Files/" + fileName); if (File.Exists(filePath)) { Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); Response.TransmitFile(filePath); Response.End(); } else { Response.Write("File not found."); } } else { Response.Write("Invalid file name."); } }Sushant TorankarRank #3,026 · 476 reputationPosted Jul 17, 2023, 11:16 AM EDT
I am trying like :
string file1 = filepath + filename
string file2 = filepath + filename
string file3 = filepath + filename
DownloadFile(file1);
DownloadFile(file2);
DownloadFile(file3);
Using same Code in DownloadFile, only file name is different.
But After downloading file1 and on downloading file2, I am getting "Server cannot clear headers after HTTP headers have been sent" error
DownloadFIle code is :
Response.Clear(); Response.ClearHeaders(); Response.Buffer = true; Response.BufferOutput = true;
Response.AddHeaders("COntent-Disposition", string.Format("attachment; filename = {0}{1}", FileName, type));
Response.Charset = ""; Response.ContentType = "application/pdf"; Response.TransmitFIle(url); Response.Flush();