Solved

Issues with "content-disposition" HTTP Header

Posted on 2007-12-06
4
1,564 Views
Last Modified: 2008-02-01
I am working with ASP.NET 2.0 and ABCpdf .NET 6.1 (from WebSupergoo). I have a number of .aspx(.vb) pages that generate reports based on the QueryString and formats everything nicely for printing using HTML and CSS. I then have a ViewPDF.aspx(.vb) that opens in a new window and uses a QueryString to determine which report to generate and uses ABCpdf's "AddImageUrl" method to create a .pdf file. So far so good.

My issue comes at the end (Line 4 of the attached code from ViewPDF.aspx.vb). I have tested in IE 7 and Firefox 2 and get the same results.
- If I set the content-disposition Header to "attachment" it uses the dynamically assigned filename, but brings up the File Download dialog, which my client isn't happy with.
- Setting the content-disposition Header to "inline" opens the .pdf document directly in the window (a more desirable modus operandi) but when going to "Save" or "Email" always uses "ViewPDF.aspx.pdf" as the filename. This isn't desirable for the user!

Is there anyway of having the document download "inline" and at the same time have a dynamically assigned filename?
Response.Expires = -1000
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", pdfData.Length.ToString())
Response.AddHeader("content-disposition", "attachment; filename=" & sbFileName.ToString)
Response.BinaryWrite(pdfData)

Open in new window

0
Comment
Question by:DerekWatling
  • 3
4 Comments
 
LVL 19

Accepted Solution

by:
SteveH_UK earned 250 total points
ID: 20419519
You may be able to solve this with an extended path, like:

http://hostname/page.aspx/Filename.pdf

That way the Save As link will generally get Filename.pdf even though page.aspx is running.
0
 
LVL 19

Expert Comment

by:SteveH_UK
ID: 20419524
You will need to use a redirected post-back so that the browser gets the adjusted page location.
0
 

Author Comment

by:DerekWatling
ID: 20420048
That works if I use something like
    http://hostname/ViewPDF.aspx/Filename.pdf?QueryString...
in the JavaScript that opens the new window.
0
 
LVL 19

Expert Comment

by:SteveH_UK
ID: 20421350
Glad you got it to work.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question