PaulW 
Member 
 
Registered: 26th Jan 03
 Location: Atherton, Greater Manchester 
User status: Offline 
 
 | 
 
I've seen it done on other sites, but I can't remember for the life of me where... 
 
I want to add links to download files from an online resources system (DOC, PDF, XLS, MDB, etc), and instead of it opening in the same window or a new window, I want it so when the user left-clicks, instead of opening it up in IE or whatever, it displays the Save Target box. 
 
Reason for this, right-clicking has been disabled on the site, so can't right-click, save-target as
 |  
PaulW 
Member 
 
Registered: 26th Jan 03
 Location: Atherton, Greater Manchester 
User status: Offline 
 
 | 
 
Or if anyone can help me with headers in asp?? 
 
code:
  
Response.AddHeader "Content-Disposition","attachment;filename="  & fileName 
Response.AddHeader "Content-Length", stream.Size 
Response.CharSet = "UTF-8"  
Response.ContentType = "application/x-msdownload" 
Response.BinaryWrite stream.Read 
  
  
 
I found that as an example, but I aint sure how to implement it.  I suppose the best way would be to call a seperate file (ie, when a download link is clicked, instead of linking straight to the file, it will open something like 
 
http://blahblah.com/filedl.asp?download=\lrc\it\p433.doc 
 
than that page runs through the above header to download the file instead of opening it??  & also closes itself, so it opens up as _blank & then closes once headers have been processed?? 
 
arrrrgggg I aint ever worked with HTTP headers before, so I'm lost! 
 
[Edited on 07-07-2004 by PaulW] 
 
[Edited on 07-07-2004 by PaulW]
 |  
Ian 
Site Administrator
 
Registered: 28th Aug 99
 Location: Liverpool 
User status: Offline 
 
 | 
 
The problem you have is that MIME types are interpretted by the browser, and its up to that to decide what to do with them.  What you're doing there is telling it that its basically a foreign ContentType and that data will follow - this is your best of the bad situation as the most the browser can usually do with this is download it somehwere - there will be no app set up to handle it.  The problem there of course is that you need to get a filename and file extension in the downloaded file, I'm sure there must be some other hacks somewhere to supply that. 
 
Don't forget - the link is to the file so you shouldn't need to worry about targetting it properly.  You don't need a new window as you're about to provide something the browser can't handle anyway, and a Save As box should follow. 
 
Make sure the output from your filedl.asp script is *only* the file (albeit with the spoofed header) and you should be OK. 
 
I'd be looking in other webmail/CMS type apps to see how they do it.  Even its its not ASP you should still be able to see how the app is fooling the browser.
 |  
Dom 
Member 
 
Registered: 13th Sep 03
 
User status: Offline 
 
 | 
 
paul, the exampl you posted will work fine mate   and like you say, just pop it into a seperate ASP file and call it or you could pop it into a function/routine and call it from that   
 
however, i would recommend that you have a butchers and www.pscode.com and look up some more examples, because there are other ways to go about it mate (cant remember though, been a long time since ive done stuff in ASP so)  
 |  
 
 |