Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.Write 1

Status
Not open for further replies.

Swi

Programmer
Feb 4, 2002
1,963
US
I am successfully saving a text file from a recordset using response.write. See below:

Code:
        if formaction = "exportcsv" Then
          For Each F In rsLog.Fields
            Head = Head & "," & F.Name
          Next
          Head = Mid(Head,2) & vbCrLf
          rsLog.MoveFirst
          Response.ContentType = "text/plain"
          Response.AddHeader "Content-Disposition", "attachment;filename=test.txt"
          Response.Write Head & rsLog.GetString(2, , ",", vbCrLf, "")

The issue is that is also saves the whole HTML page. Am I doing something wrong?

Thanks.

Swi
 
Other than thinking that ASP can create and save a file client side, Nope.

Either:

Use The FileSystemObject to create the text file server side THEN present it as a download link.

Or use Response.BinaryWrite to stream the data to the useragent

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks. I just used the FSO method.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top