Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save target as...

Status
Not open for further replies.

kvoguy

IS-IT--Management
Nov 15, 2002
34
BE
Hello,

Is it possible in asp/JS/... when one of the visitors click with the left mousebutton on a documentlink that this file been saved automatically with save target as...

So they don't have to rightclick and choose this option. It should be with te left mousebutton?

thanks advance...

 
If you want to force a download you can change the response type so that the browser does not recognise it. i.e.


<%
' Constants for Reading Text File
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const TristateFalse = 0
Const TristateMixed = -2
Const TristateTrue = -1
Const TristateUseDefault = -2

' File System Objects
Dim FSO
Dim TS

' Server File (this is the REAL name of the file)
Dim strFile: strFile = Server.MapPath(&quot;saveme.gif&quot;)

' File to Save As (this is the name you want to tell the browser)
Dim strFileSave: strFileSave = &quot;saved.gif&quot;

' Tell Browser what the file name is, so it doesn't try to save as &quot;default.asp&quot;
Call Response.AddHeader(&quot;Content-Disposition&quot;,&quot;attachment; filename=&quot;&quot;&quot; & strFileSave & &quot;&quot;&quot;&quot;)

' Write out content-type that will FORCE user to SAVE FILE.
' &quot;image/gif&quot; will display in browser
Response.ContentType = &quot;bad/type&quot;

' Initialize File System Object
Set FSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

' Open TextStream for Reading
Set TS = FSO.GetFile(strFile).OpenAsTextStream(ForReading,TristateTrue)

' TS.ReadAll DOES NOT WORK. Every Byte must be read and written individually.
' I think you can read them in Chucks, but this was easier. If you know how to
' Read chunks... go ahead, read chunks ;)
Do While Not (TS.AtEndOfStream)
' Output MUST be BinaryWrite
Response.BinaryWrite(TS.Read(1))
Loop

' Clean up
TS.Close
Set TS = Nothing
Set FSO = Nothing

%>


Hope this helps.
 
Monday I'll will implement it in my code at work. This seems to work at home here

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top