views:

693

answers:

3

Hello all. 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?

+3  A: 

Add the following header in your ashx-file:

context.Response.AddHeader("content-disposition", "attachment;filename=PUTYOURFILENAMEHERE.pdf");
context.Response.ContentType = "application/pdf";
Pbirkoff
+1 for being faster :)
Diadistis
In this case browser proposes to download file when the Adobe plug-in is installed...
w1z
+1  A: 

Try inline content-disposition, however I have to check this:

Response.ContentType = "application/pdf"; 
Response.AppendHeader("content-disposition", "inline; filename=" + name ); 
Mike Chaliy
Mike, it's great. Thank you from Kharkov, GlobalLogic. Мир тесен ;)
w1z
:), but as far I know this will not work... А кто ты конкртейней?
Mike Chaliy
Вроде работает, проверил только что. Ты лично меня не знаешь, вместе мы не работали. Я работаю у Бережного. Был на паре твоих докладов на Uneta. CodeContracts интересная штука :)
w1z
A: 
Use     


 Response.Clear();
 Response.ContentType = "application/octet-stream";
 Response.AddHeader("Content-Disposition", "attachment; filename=Report.PDF");                                            
 Response.WriteFile(Server.MapPath("~/YourPath/Report.PDF"));
 Response.End();
Priyan R