Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading files using ASP.NET .ashx modules

I have ASP.NET page with an iframe on it for displaying some pdf reports on this page. When user select the report type from dropdown, I add the needed for report data into the ASP.NET Session and change the attribute "src" of the iframe to .ashx module address which generates the .pdf report. But if Adobe glug-in for viewing .pdf files in browser is not installed, browser proposes to save report file and name of the proposed file is "HandlerName.ashx". But I want to make the browser proposed to save the file with the name "Report.pdf". Can I do this? Are there any workarounds?

like image 571
w1z Avatar asked Feb 23 '10 11:02

w1z


1 Answers

Add the following header in your ashx-file:

context.Response.AddHeader("content-disposition", "attachment;filename=PUTYOURFILENAMEHERE.pdf");
context.Response.ContentType = "application/pdf";
like image 113
Pbirkoff Avatar answered Nov 06 '22 05:11

Pbirkoff