在IE進行文檔鏈接時如果遇到OLE支持的文檔IE會自動調用相應程序打開它有時候這種功能並不是我們所需的雖然我們可以提醒用戶用鼠標右鍵>目標另存為命令來下載文檔但這樣畢竟不太友好本文描述了利用FSO及Stream方法實現IE直接下載文檔
<%@ language=vbscript codepage=%>
<%
Filename must be input
if Request(Filename)= then
responsewrite <h>Error:</h>Filename is empty!<p>
else
call downloadFile(replace(replace(Request(Filename)\)/))
Function downloadFile(strFile)
make sure you are on the latest MDAC version for this to work
get full path of specified file
strFilename = serverMapPath(strFile)
clear the buffer
ResponseBuffer = True
ResponseClear
create stream
Set s = ServerCreateObject(ADODBStream)
sOpen
Set as binary
sType =
load in the file
on error resume next
check the file exists
Set fso = ServerCreateObject(ScriptingFileSystemObject)
if not fsoFileExists(strFilename) then
ResponseWrite(<h>Error:</h>&strFilename& does not exists!<p>)
ResponseEnd
end if
get length of file
Set f = fsoGetFile(strFilename)
intFilelength = fsize
sLoadFromFile(strFilename)
if err then
ResponseWrite(<h>Error: </h>Unknown Error!<p>)
ResponseEnd
end if
send the headers to the users Browse
ResponseAddHeader ContentDispositionattachment; filename=&fname
ResponseAddHeader ContentLengthintFilelength
ResponseCharSet = UTF
ResponseContentType = application/octetstream
output the file to the browser
ResponseBinaryWrite sRead
ResponseFlush
tidy up
sClose
Set s = Nothing
End Function
end if
%>
From:http://tw.wingwit.com/Article/program/net/201311/12831.html