Click to See Complete Forum and Search --> : Download a file without right click, 'save target as...'


chrisw184
06-29-2004, 04:55 AM
Hi

I have a site for a customer who has text links to PDF files.

The PDF files are supposed to be for downloading to the users computer and not opeining in the Browser (I have jpg images for viewing online rather than the high-res PDF's).

However, my client does not want to have to right click the text link and then choose 'save target as...' to be able to save the PDf to his computer.

Is there any code I can add so that the user can click the text link as normal and it then opens the 'do you wish to open or save the file' dialogue box.

I have seen this implemented using PHP - http://www.stadtaus.com/en/php_scripts/download_center_lite/ but we use ASP on our server.

Any help would be much appreciated.

Regards

Chris W

ray326
06-29-2004, 08:16 AM
You can stream the file out after setting appropriate headers like content-type application/octet-stream and content-disposition attachment with filename but you can't guarantee what action the browser will take. IE usually ignores HTTP headers, e.g, but even that is dependent on the OS it's running on.

AdamGundry
06-29-2004, 08:17 AM
You can do it in ASP in nearly the same way as PHP. Bear in mind my experience is with the latter, so this might not be perfect (stolen from somewhere on MSDN and modified):

Response.buffer = TRUE
Response.ContentType = "application/pdf"
Response.AddHeader "content-disposition","attachment; filename=myfile.pdf"

Dim vntStream

Set oMyObject = Server.CreateObject("MyObject.BinRead")
vntStream = oMyObject.readBinFile("filename\on\server.pdf")

Response.BinaryWrite(vntStream)

Set oMyObject = Nothing

Response.End

Adam