0

I need to create and send a TXT file on the fly using classic asp. I know how to creates this file saving it into a directory and then send it using Server.CreateObject("ADODB.Stream") ... but what I wanted is to avoid saving it in the directory and just create and send on the fly. In this case the TXT file is a list of records extracted from a MySql DB. One each line ...

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

Is it possible to do this ...meaning create a file in memory to strem/send ... orthere is no option but creating and saving it on disk before and send later ??

Lawrence
  • 11
  • 7

1 Answers1

0

The following will work. Note: my example below assumes your recordset returns one field.

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
Robert S
  • 496
  • 4
  • 14