精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● ASP>>ASP技巧>>强迫doc文件下载

主题:强迫doc文件下载
发信人: i_am_trueman(粗蚊)
整理人: i_am_trueman(2003-10-22 16:49:55), 站内信件
【 在 qcrsoft 的大作中提到:】
:呃……以前yahoo说过,好象修改iis配置,加http头什么的,记不太清了
:......
嗯,刚才在本版搜了一下,发现了jason0717的例程:
Dim Stream 
Dim Contents 
Dim FileName 

FileName="aaa.htm" 

Response.ContentType="application/octet-stream" 
Response.AddHeader "content-disposition", "attachment; filename=" & FileName 

Set Stream=Server.CreateObject("ADODB.Stream") 
Stream.Open 
Stream.LoadFromFile Server.MapPath(FileName) 
Contents=Stream.ReadText 
Response.BinaryWrite Contents 

Stream.Close 
Set Stream=Nothing 
---------

这个例程是对应纯文本的,我改了一下,变成支持doc的,如下:
Response.AddHeader "Content-Disposition", "attachment;filename=tm.doc"
response.ContentType="application/x-msword"

Const adTypeBinary = 1
Dim strFilePath

strFilePath = "c:\a.doc"

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing



----
 

[关闭][返回]