Link to home
Start Free TrialLog in
Avatar of zombeen
zombeen

asked on

download , not open pdf files

Dear experts.

I hv a problem with pdf files. In my site there are a number of links for pdf files. If you left click the pdf file, it tries to open in the browser only. I've heard through Content-disposition you can force IE/NN to force download the file rather than open. Can anyone throw more light on how to do this

Thks in advance
SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
zombeen,

hongjun's answer might work.  But just in case it doesn't, try this instead...

<%
Response.AddHeader "content-disposition","attachment; filename=yourfile.pdf"
ContentType = "bad/type"
%>

HOPE THIS HELPS!

Webmonkey
SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zombeen
zombeen

ASKER

thks u all for the comments. Hongjun's and webmonkey's comments seem the most valuale coz o their simplicity. Nothing taking away from Fritz though.

I had one question though. The asp page will have many links for pdf files on the pags and all of them dynamic (searched using combination of FSO & ADO)... How then will I change my Response.Header line...Where shd it be placed?

Thks
Zombeen
Avatar of zombeen

ASKER

Thks all for your comments. I wld like to go for the simpler options given by hongjun and webmonkey..nothing taking away from Frtiz' reposnse though. That might well be the option I hv to choose.

My situation is that i have multiple links for pdf files in my asp page, all called dynamically thru FSO & ADO. How will I tackle this in  the statement you have provided below , and where shd it be placed (in the head section?)

Thks
Zombeen
Avatar of zombeen

ASKER

Thks all for your comments. I wld like to go for the simpler options given by hongjun and webmonkey..nothing taking away from Frtiz' reposnse though. That might well be the option I hv to choose.

My situation is that i have multiple links for pdf files in my asp page, all called dynamically thru FSO & ADO. How will I tackle this in  the statement you have provided below , and where shd it be placed (in the head section?)

Thks
Zombeen
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
vijay7248's approach will work. Pass filename as querystring and set filename of Response.AddHeader using the passed in querystring.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zombeen

ASKER

thks a ton for so many comments... and sorry for late response.. i m going to check some of these today/tom, and get back here, hopefully with my problem solved
Here's a sub that will download a file  just call it with teh filename,pathname
This was taken from another post and edited by me as I had the same question recently.
Private Sub DownlaodFile(File, PathName)
     Dim objFSO
     Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
     Response.Clear
     Response.Buffer = true          
     If objFSO.FileExists(PathName) Then
                                Response.AddHeader "Content-Type", "application/file-download"
                                Response.AddHeader "Content-Disposition", "attachment; filename=" & File
          Dim objStream
          Set objStream = Server.CreateObject("ADODB.Stream")
          objStream.Open
          objStream.Type = 1
          Response.CharSet = "UTF-8"
          objStream.LoadFromFile(PathName)
          Response.BinaryWrite(objStream.Read)
          objStream.Close
          Set objStream = Nothing
     Else
          Response.Write("No such file exists.")
     End If
     Set objFSO = Nothing
End sub %>
Which is a variation of what I posted above, no?

Fritz the Blank
zombeen, good luck
Avatar of zombeen

ASKER

thks to all!. they were all wonderful solutions in their own right
sorry if i hv missed alotting points to anyone

Zombeen
You're welcome and good luck with the project.

Fritz the Blank
Thanks for accepting my answer zombeen

Good luck!

-Vijay