Sjoerd
Sjoerd

Reputation: 75649

Serve PDF file using ASP.NET with custom filename

I currently have a page ReportPDF.aspx which creates a PDF and writes it to the response. I set the filename using the Content-Disposition header. However, if someone uses "Save link as..." on the link, it still saves the file as ReportPDF.aspx.

How can I use Report.pdf as filename, while still dynamically creating the PDF?

Upvotes: 0

Views: 855

Answers (4)

Sjoerd
Sjoerd

Reputation: 75649

I solved it by linking to

/ReportPDF.aspx/d6bea1cb-c630-47d6-8735-db7b72713fde/ReportData.pdf

And using the Request.PathInfo variable to get the parameter.

Upvotes: 0

mathieu
mathieu

Reputation: 31202

I had the same issue, and have it work with "clean" names :

  • no spaces
  • only letters and numbers

Upvotes: 0

Allison Lock
Allison Lock

Reputation: 2393

Could you use URL rewriting so that the URL is actually Report.pdf, which is then rewritten to ReportPDF.aspx server-side?

Upvotes: 0

Nathan
Nathan

Reputation: 6216

I'm afraid that's a behaviour of the browser that the client is using - some will (correctly) use the content-disposition header and some won't... sorry.

Upvotes: 0

Related Questions