fso|stream| Download
When IE is linking to documents, if you encounter OLE supported documents, IE will automatically call the appropriate program to open it, sometimes this function is not what we need, although we can remind users to use the right mouse button--> "target Save As ..." command to download the document, but this is not very friendly, This article describes the use of FSO and stream method to achieve IE direct download documents.
<%@ Language=vbscript codepage=65001%>
<%
' Filename must be input
If Request ("Filename") = "" Then
Response.Write "Else
Call DownloadFile (replace (Request ("Filename", "\", ""), "/", ""))
Function DownloadFile (strfile)
' Make sure your are on the latest MDAC version of To work
' Get full path of specified file
strFileName = Server. MapPath (strfile)
' Clear the buffer
Response.Buffer = True
Response.Clear
' Create stream
Set s = Server.CreateObject ("ADODB.") Stream ")
S.open
' Set as Binary
S.type = 1
' Load in ' file
On Error Resume Next
' Check the file exists
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
If not FSO. FileExists (strFileName) Then
Response.Write ("Response.End
End If
' Get length of file '
Set f = fso. GetFile (strFileName)
Intfilelength = F.size
S.loadfromfile (strFileName)
If Err Then
Response.Write ("Response.End
End If
' Send the headers to the users Browse
Response.AddHeader "Content-disposition", "attachment"; Filename= "&f.name
Response.AddHeader "Content-length", intfilelength
Response.Charset = "UTF-8"
Response.ContentType = "Application/octet-stream"
' Output the file to the ' browser
Response.BinaryWrite S.read
Response.Flush
' Tidy up
S.close
Set s = Nothing
End Function
End If
%>