Solved

Issues with "content-disposition" HTTP Header

Posted on 2007-12-06
4
1,566 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't Find the Homepage on my site 4 40
How does GeoJson relates to Leaflet and Mapbox? 4 42
Error Handler 8 36
Why am I losing my session variable value 11 31
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…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

733 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