Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net C# Multiple Documents on One Response Object

I have this code

private void writeReport(IReport report, string reportName)
{
    string reportString = report.makeReport();
    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] encodedReport = encoding.GetBytes(reportString);
    Response.ContentType = "text/plain";
    Response.AddHeader("Content-Disposition", "attachment;filename="+ reportName +".txt");
    Response.OutputStream.Write(encodedReport, 0, encodedReport.Length);
    Response.End();
}

but I have 3 documents that I need to send to the client. I'd rather not have to make the user click 3 buttons to get them the 3 txt files. Is there a way to send all 3 on one reponse?

like image 329
jim Avatar asked Jul 03 '09 08:07

jim


2 Answers

Nope, multipart attachments for download (like as in email) aren't supported for security reasons. It's called a "drive-by download."

Note that Gmail handles this by dynamically zipping up the files. You should too. http://forums.asp.net/t/1240811.aspx

like image 179
Scott Hanselman Avatar answered Sep 28 '22 03:09

Scott Hanselman


This can be done according to the article "Download multiple files in one http request" on motobit.com.

However it's not how HTTP was designed and following those steps may break at any time depending on client and server configuration.

like image 26
Alex Angas Avatar answered Sep 28 '22 03:09

Alex Angas