开发者

Solutions to inline filename content disposition and injecting a dynamic filename for saving action

Essentially I am streaming a pdf from memory to the user's browser. I would like to allow the system user to be able to hit save in adobe (in browser) and have the filename pre-filled with a dynamic value (e.g. last name of the customer).

I've read a bit about this problem so far, it seems that content disposition header setting the inline filename isn't implemented correctly.

I have read that adobe takes the filename from the page that generates the pdf. I.e. if the page name is pdfviewer.aspx, then the pre-filled value of the pdf's filename is pdfviewer.pdf.

I am looking for a work around. My original idea was for a http handler which will generate and push out the pdf, and have the web config as such:

 <add verb="*" path="*.ashx" type="Logic.PDFHandler" />

This way when I dynamically set the link to "lastname.ashx", it should run the code in PDFHandler, while the url will be somthing like "...\lastname.ashx". I seem to be able to get this to work in a proof of concept (substituting the generation of the pdf with a simple repsonse.write("hello world")), but I'm just wondering, if there are any better work 开发者_开发知识库arounds?

Note: The proof of concept only works in IE and I'm happy for it as it is the browser targeted for this intranet application.


ASP.NET routing would let you route /GeneratePDF/{id}/{lastname}.pdf or something to your handler.


The way to make the browser ask you to save the PDF with a given name is as follows:

// code runs on ASP.NET server
Response.Clear();
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}".
   fileName);
Response.ContentType = "application/pdf";
// stream PDF to response object
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜