Forcing a download
-
I'm looking for info on how to make any file (.pdf, .jpg, .doc, .anything) forced as a download even if the browser (mainly IE) thinks it knows what to do with that kind of file. For example: I have a series of links, I want the user to only have to left click to initiate the download. If they click on a .jpg file it will try to open it in the browser and just show the image. I want it to prompt a user for downoad regarless of file type. I am using ASP to develop this project currently. TIA,
Wally Atkins
Newport News, VA, USA -
I'm looking for info on how to make any file (.pdf, .jpg, .doc, .anything) forced as a download even if the browser (mainly IE) thinks it knows what to do with that kind of file. For example: I have a series of links, I want the user to only have to left click to initiate the download. If they click on a .jpg file it will try to open it in the browser and just show the image. I want it to prompt a user for downoad regarless of file type. I am using ASP to develop this project currently. TIA,
Wally Atkins
Newport News, VA, USAPretty simple actually ...
'Buffer the response
Response.Buffer = True'Create a Stream object
Const adTypeBinary = 1
Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = adTypeBinary
adoStream.LoadFromFile "c:\mypic.jpg" 'Need absolute path to file'Prepare the header information
Response.AddHeader "Content-Disposition", "attachment; filename=mypic.jpg"
Response.AddHeader "Content-Length", "1024" 'You can get this dynamically using FileSystemObject
Response.Charset = "UTF-8"
Response.ContentType = "image/jpeg" 'There are different possibilities here too'Send the data
Response.BinaryWrite objStream.Read'Flush the response
Response.Flush'Clean up
objStream.Close
Set objStream = NothingWally Atkins
Newport News, VA, USA -
Pretty simple actually ...
'Buffer the response
Response.Buffer = True'Create a Stream object
Const adTypeBinary = 1
Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = adTypeBinary
adoStream.LoadFromFile "c:\mypic.jpg" 'Need absolute path to file'Prepare the header information
Response.AddHeader "Content-Disposition", "attachment; filename=mypic.jpg"
Response.AddHeader "Content-Length", "1024" 'You can get this dynamically using FileSystemObject
Response.Charset = "UTF-8"
Response.ContentType = "image/jpeg" 'There are different possibilities here too'Send the data
Response.BinaryWrite objStream.Read'Flush the response
Response.Flush'Clean up
objStream.Close
Set objStream = NothingWally Atkins
Newport News, VA, USAI found a code that goes a little further... no only does it force the download...but it allows you to list all the files in a specified (or dynamically generated) path, but it lets you select the file that you want to download, sort the files but type, name or weight. Go to the page that explains it all see ya... Jon GET TO KNOW ME