JavaScrip Zone


新发表

新评论

留言信息

链接收藏

『中国群落博客』

免费注册博客通道

快速登陆


实现文件下载而不是由ie打开的代码

<%
Const ForReading=1
Const TristateTrue=-1 'Unicode
Const FILE_TRANSFER_SIZE=16384 '16k

'Use the following line for IIS4/PWS - this is the default for IIS5
Response.Buffer = True

Function TransferFile(path, mimeType, filename)
Dim objFileSystem, objFile, objStream
Dim char
Dim sent
send=0
TransferFile = True

Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.GetFile(Path)
Set objStream = objFile.OpenAsTextStream(ForReading, TristateTrue)

Response.AddHeader "content-type", mimeType
response.AddHeader "Content-Disposition","attachment;filename="&filename  
Response.AddHeader "content-length", objFile.Size

Do While Not objStream.AtEndOfStream
    char = objStream.Read(1)
    Response.BinaryWrite(char)
    sent = sent + 1
    If (sent MOD FILE_TRANSFER_SIZE) = 0 Then
        Response.Flush
        If Not Response.IsClientConnected Then
            TransferFile = False
            Exit Do
        End If
    End If
Loop

Response.Flush
If Not Response.IsClientConnected Then TransferFile = False

objStream.Close
Set objStream = Nothing
Set objFileSystem = Nothing
End Function

Dim path, mimeType, sucess
'Server.MapPath(path)
path = "C:\Inetpub\wwwroot\help.gif"
mimeType = "application/x-msdownload"  
sucess = TransferFile(path, mimeType,"help.gif")
Response.End
%>

                                                                 2006-7-18 13:26:17

Posted by jser | 阅读全文() | 回复(0) | 引用通告() | 编辑

..................................................
博客的精神于写自己某一刻的思想或心动!
..................................................
当然要是你愿意就是拿来做记事本也可以!
..................................................
群落博客将提供全程免费服务!免费注册!
..................................................
欢迎您成为群落博客的成员!使用之前请先看系统帮助>>>>系统帮助
..................................................

免费注册群落博客【点击完成注册】
..................................................

发表评论:

    昵称:
    密码: (游客无须输入密码)
    主页:
    标题: