badallen
badallen

Reputation: 1127

Setting PDF file name dynamically

I hope I am able to explain my situation accurately.

I have an ASP.NET page that dumps out PDF files for the users with the following code:

Response.ContentType = "application/pdf";                
Response.AppendHeader("content-disposition", string.Format("inline; filename={0}", getFileName(DateTime.Now)));

The reason why I use "inline" instead of "attachment", so I can force the users to view the PDF directly in the browsers instead of opening up the acrobat to view the PDFs. Everything is fine so far, but when users want to save a file, the file name which should be set to "getFileName(DateTime.Now)", instead it just takes the name of the page like myPDFpage.pdf.

Is there anyway, without setting the content-disposition to "attachment", for the users to save the file with the name I specify with the getFileName() method?

Thanks in advance. badallen

Upvotes: 2

Views: 3340

Answers (2)

Jay Riggs
Jay Riggs

Reputation: 53593

I understand what you're trying to do is not possible because there are problems wth the 'inline' disposition type (I gather it's a PDF and/or browser issue).

I was struggling with the same issue and found this article which promises a solution:
How to show or download a pdf file from an ASP.NET 2.0 page (iTextSharp version)

The basic problem is that by default PDFs will be saved with a base name (name without filename extension) of the page it's served up on; the article shows how you can use a dynamically named HttpHandler to deliver PDFs and control the filename.

Fair warning: I haven't tried this yet myself so I can't tell you if it will work.

Upvotes: 0

Mitchel Sellers
Mitchel Sellers

Reputation: 63136

This is a simple behavior of the way that acrobat handles the file when you have it open inline. As far as I know there is not a way to dictate this when opening inline, as that becomes the responsibility of Acrobat.

Upvotes: 1

Related Questions