Download a file without right click, 'save target as...'

liunx

Guest
Hi<br />
<br />
I have a site for a customer who has text links to PDF files.<br />
<br />
The PDF files are supposed to be for Download <!--more-->ing to the users computer and not opeining in the Browser (I have jpg images for viewing online rather than the high-res PDF's).<br />
<br />
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.<br />
<br />
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.<br />
<br />
I have seen this implemented using PHP - <!-- m --><a class="postlink" href="http://www.stadtaus.com/en/php_scripts/Download">http://www.stadtaus.com/en/php_scripts/Download</a><!-- m --> <!--more-->_center_lite/ but we use ASP on our server.<br />
<br />
Any help would be much appreciated.<br />
<br />
Regards<br />
<br />
Chris W<!--content-->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.<!--content-->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):<br />
<br />
Response.buffer = TRUE<br />
Response.ContentType = "application/pdf"<br />
Response.AddHeader "content-disposition","attachment; filename=myfile.pdf"<br />
<br />
Dim vntStream<br />
<br />
Set oMyObject = Server.CreateObject("MyObject.BinRead")<br />
vntStream = oMyObject.readBinFile("filename\on\server.pdf")<br />
<br />
Response.BinaryWrite(vntStream)<br />
<br />
Set oMyObject = Nothing<br />
<br />
Response.End<br />
<br />
Adam<!--content-->
 
Back
Top