Solved

Issues with "content-disposition" HTTP Header

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

867 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

12 Experts available now in Live!

Get 1:1 Help Now