Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF Handler : content-disposition filename

I am outputting a PDF file in a Web browser (IE8) HttpContext.Response.writefile(fileName) and it works great. When I try to save the file, it will give me the name of the ashx handler as a default. I would like to actually pass the real name.

I tried to add header information as follow:

context.Response.AddHeader("content-disposition", "attachment; filename=" + fileInfo.Name);

And it works but I do not want the user to have to choose between open and save, i want the file to open normally and if the user chooses to save it then the dialog would give him/her the default filename.

I tried also:

context.Response.AddHeader("content-disposition", "inline; filename=" + fileInfo.Name);

Or just, like Scott Hanselman suggested in his blog.

context.Response.AddHeader("content-disposition", "filename=" + fileInfo.Name);

None of those work for me. Does anybody have any ideas?

like image 680
user2062308 Avatar asked Feb 11 '13 18:02

user2062308


People also ask

What is content disposition attachment filename?

Content-Disposition is an optional header and allows the sender to indicate a default archival disposition; a filename. The optional "filename" parameter provides for this. This header field definition is based almost verbatim on Experimental RFC 1806 by R. Troost and S.

What is content disposition inline?

1. Content Disposition Type : inline: This indicates that data should be displayed automatically on prompt in browser. attachment: This indicates that user should receive a prompt (usually a Save As dialog box) to save the file locally on the disk to access it.

What is content disposition S3?

S3 provides multiple ways to set the Content-Disposition header of an object being downloaded, two of the main ways are: Set Content Disposition parameter on upload – works for new objects. Set response-content-disposition parameter in request – works for an existing object however requires a signed URL.


2 Answers

See test cases at http://greenbytes.de/tech/tc2231/#inlwithasciifilenamepdf - it seems that this is simply a missing feature in IE.

like image 165
Julian Reschke Avatar answered Oct 02 '22 00:10

Julian Reschke


I also came across this problem. What helped me was to also set the contenttype to application/pdf (instead of application/x-pdf, which is outdated)

response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline; filename=\"Report.pdf\"");
like image 31
zeisi Avatar answered Oct 01 '22 22:10

zeisi