日期:2014-05-16  浏览次数:20942 次

一个小问题 txt 另存为
有一个txt文件,需要下载到客户端  而不是网页打开

Response.redirect("123.txt")

什么方法用户可以另存为 123.txt 到本地 而不是浏览器打开


------解决方案--------------------
本帖最后由 chinmo 于 2013-04-18 14:05:34 编辑
<% 
Response.Buffer=true 
'取得要下载的文件,如果不为空。就下载 
dim url,trueurl 
url="下载文件路径和下载文件名"    
fname=Request("filename")    
if fname<>"" then       
trueurlurl=server.MapPath("/") &url    
end if   
set objFso=server.CreateObject("scripting.filesystemobject")    
set fn=objFso.GetFile(trueurl)    
flsize=fn.size    
flname=fn.name    
set fn=nothing    
set objFso=nothing        
set objStream=server.CreateObject("adodb.stream")    
objStream.Open     
objStream.Type=1    
objStream.LoadFromFile url        
select case lcase(right(flname,4))       
case ".asf"       
ContentType="video/x-ms-asf"       
case ".avi"       
ContentType="video/avi"       
case ".doc"       
ContentType="application/msword"       
case ".zip"       
ContentType="application/zip"       
case ".xls"       
ContentType="application/vnd.ms-excel"       
case ".gif"       
ContentType="image/gif"       
case ".jpg","jpeg"       
ContentType="image/jpeg"       
case ".wav"       
ContentType="audio/wav"       
case ".mp3"       
ContentType="audio/mpeg3"       
case ".mpg", "mpeg"       
ContentType="video/mpeg" 
case ".rtf"       
ContentType="application/rtf"       
case ".htm","html"       
ContentType="text/html"       
case ".txt"       
ContentType="text/plain"   
Case ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"         
Response.Write "受保护文件,不能下载."         
Response.End       
case else       
ContentType="appliation/octet-stream"    
end select     
Response.AddHeader "Content-Disposition", "attachment; filename="&flname    
Response.AddH