I am trying to Download multiple files using asp.net. I have a Button called DownloadFileButton and a ArrayList called FilePath(It holds all the File paths).
So when i click the Download Button only 1 file is downloaded(the first file in the FilePath List). Because Response.End() causes the script to stop processing. when i comment out the Response.End() then i get an exception at Response.ClearHeaders().
how to overcome this?
My Code:
protected void DownloadFileButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < FilePath.Count; i++)
{
string path = FilePath[i];
FileInfo file = new FileInfo(path);
if(file.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.Flush();
Response.TransmitFile(file.FullName);
Response.End();
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…