1
下面的ASP代码抓取了一个文件(thisoutfile--其中包含一个GUID作为文件名)的内容并将其流式传输到浏览器,并提供建议的文件名以保存为。这适用于除chrome外的所有浏览器,即使文件名(thisfname)是单个字,文件名所提供的也是脚本本身的名称。如果你真的将文件保存为xls或pdf,那么它可以保存它。Chrome不遵守ado.stream文件名
任何想法为什么?
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile(thisoutfile)
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(f.Path)
dataSize = f.size
Response.Buffer = true
Response.CharSet = "UTF-8"
Response.clear
select case ext
case "xls"
response.contentType="application/vnd.ms-excel"
case else
Response.ContentType = "application/x-unknown" ' arbitrary
end select
Response.AddHeader "Content-Length", dataSize
Response.AddHeader "Content-Disposition","attachment;filename=""" & thisfname & ""
Response.flush
do while not adoStream.eos
Response.BinaryWrite adoStream.Read(1024 * 8)
Response.flush
loop
Response.End()
adoStream.close
set adoStream=nothing
set f=nothing
set fs=nothing
是的就是这样 - 谢谢 – derekcohen 2011-06-01 20:18:44