我需要创建并发送一个TXT文件在飞行使用经典的asp。我知道如何创建这个文件,将它保存到一个目录中,然后使用Server.CreateObject("ADODB.Stream")发送它……但我想要的是避免将其保存在目录中,而只是动态创建和发送。在本例中,TXT文件是从MySql DB提取的记录列表。每行一行。
strSQL = "SELECT * FROM mydb WHERE condition='ok';"
Set rs = my_conn.Execute(strSQL)
Response.Buffer = False
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
Response.ContentType = "application/x-unknown"
Response.Addheader "Content-Disposition", "attachment; filename=recordsfile.txt"
Response.BinaryWrite (dunno how to create a file with rs("field01") & " _ " & rs("field02") & vbnewline
objStream.Close
Set objStream = Nothing
有没有可能做到这一点,在内存中创建一个文件...meaning流/发送...或者没有其他选择,只能在磁盘上创建并保存,然后再发送?
发布于 2017-03-03 15:00:38
下面的方法将会起作用。注意:下面的示例假设您的记录集返回一个字段。
strSQL = "SELECT * FROM mydb WHERE condition='ok';"
Set rs = my_conn.Execute(strSQL)
if not rs.eof then
response.contentType = "application/octet-stream"
response.addHeader "Content-Disposition", "attachment; filename=recordsfile.txt"
do until rs.eof
response.write rs(0).value & vbcrlf
rs.movenext
loop
end if
https://stackoverflow.com/questions/42567673
复制相似问题