Force Download Part 2

T

tma

Short of zipping my file, are there any other alternatives to the below?

I'm trying to add anchors in code and I need the link to force a download of
the .pdf rather than open a new window or worse, open the file in the
current client browser window. Is there something I can change about the
anchor itself to force this behavior? I did not have any success with the
"content-disposition" articles suggested.

Here is my very normal anchor code:

a = New HtmlAnchor

a.HRef = "http://www.someURL/Registration.pdf"

a.InnerText = "Print Application"

a.Target = "_blank"
 
R

Raterus

As long as you are linking directly to the pdf file on your webserver, the webserver (most likely) is going to send the HTTP headers in a way so your browser will attempt to open it up. To avoid this, you are going to have to create your own download page, which sets the headers you need to show the "save as" box, and then stream the file from your webserver to the client. Then your href in the hyperlink will look something like this

a.href="http://www.someurl.com/download.aspx?file=registration.pdf"

If you mentioned you were looking at articles about "content-disposition", you'll have to use this in the download page.

--Michael
 
B

bruce barker

if you never want pdf's to display from this site, you can update the server
mime type mapping for the vdir. a good solution would to create a seperate
vdir under your main vdir (say called download), that you update the mime
mappings, and a another vdir (using the same dir, say called display) that
has the standard mapping. then

mysite/download/mypdf.pdf

will use the save as, while

mysite/display/mypdf.pdf

will load in the browser

-- bruce (sqlwork.com)


As long as you are linking directly to the pdf file on your webserver, the
webserver (most likely) is going to send the HTTP headers in a way so your
browser will attempt to open it up. To avoid this, you are going to have to
create your own download page, which sets the headers you need to show the
"save as" box, and then stream the file from your webserver to the client.
Then your href in the hyperlink will look something like this

a.href="http://www.someurl.com/download.aspx?file=registration.pdf"

If you mentioned you were looking at articles about "content-disposition",
you'll have to use this in the download page.

--Michael
 
T

tma

Can you point me in a direction for how to go about updating the MIME types
for that vdir where I want download only?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top