Solved

Issues with "content-disposition" HTTP Header

Posted on 2007-12-06
4
1,562 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now