开发者

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?


Add the following header in your ashx-file:

context.Response.AddHeader("content-disposition", "attachment;filename=PUTYOURFILENAMEHERE.pdf");
context.Response.ContentType = "application/pdf";


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

Response.ContentType = "application/pdf"; 
Response.AppendHeader("content-disposition", "inline; filename=" + name ); 


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜