Temporary txt,csv Files?

M

MDW

Hey all

I've got a web-based "database admin console" that uses ADOX, etc. to query a database and return the tables, columns, etc to a form that I can then use to build SQL statements to run against that database. It's very "generic" - i.e., everything is dymanically created but pretty handy to have

If you send it a "SELECT" statement, it can print out a table on the screen showing your recordset. No big deal. What I'd also like to include is some way for users to get that output in a comma- or tab-delimited text file that they can use however they like. There are two ways I know of to accomplish thi

1) Create a big string as I step through the recordset - (strOutput = strOutput & "'" & objRS(I) & "," .....) and then slap strOutput into a <textarea>. This is probably not desirable because the user would have to copy all the content in that <textarea> and manually paste it into Notepad or whatever

2) Use the FSO. However, my limited experience with the FSO leads me to believe that I'd have to SAVE the resultant file before I can send it to users. I don't want to do that.

Does anyone have any suggestions about how else I can accomplish this? Or, if FSO is the way to go (which I suspect it is), bear in mind that my only exposure to FSO is in the context of .vbs files....are there any special tricks you need to use for ASP

TIA
 
P

Patrice

Youn can "Response.Write" the file content to the browser (string
concatenation is still not recommended)

Using :
Response.Clear
Response.AddHeader
"Content-disposition","attachment;filename=basenameAAMMJJ.txt"

Before sending the content will alow to raise the usual download dialog. The
user will be able to save the file on his disk or to open the file (with the
program associated with the txt extension).

Patrice

MDW said:
Hey all,

I've got a web-based "database admin console" that uses ADOX, etc. to
query a database and return the tables, columns, etc to a form that I can
then use to build SQL statements to run against that database. It's very
"generic" - i.e., everything is dymanically created but pretty handy to
have.
If you send it a "SELECT" statement, it can print out a table on the
screen showing your recordset. No big deal. What I'd also like to include is
some way for users to get that output in a comma- or tab-delimited text file
that they can use however they like. There are two ways I know of to
accomplish this
1) Create a big string as I step through the recordset - (strOutput =
strOutput & "'" & objRS(I) & "," .....) and then slap strOutput into a
<textarea>. This is probably not desirable because the user would have to
copy all the content in that said:
2) Use the FSO. However, my limited experience with the FSO leads me to
believe that I'd have to SAVE the resultant file before I can send it to
users. I don't want to do that.
Does anyone have any suggestions about how else I can accomplish this? Or,
if FSO is the way to go (which I suspect it is), bear in mind that my only
exposure to FSO is in the context of .vbs files....are there any special
tricks you need to use for ASP?
 
M

MDW

Excellent!! Thanks so much

FYI, I didn't do concat (and I don't employ it for printing on the screen), I used a loop.

I think I'm gonna reuse this admin page for every site I work on -- it's turning out to be darn useful

Follow-up question, though: On that dialog box, the default file type is *.htm,*.html. Is there any way I can make the default type *.*

Here's the code I use

If Request.Form("Save") <> "" Then ' The user wants to save the recordse

strExt = Request.Form("Save"

Select Case UCase(strExt

Case "TXT

strSep = vbTa

Case "CSV

strSep = ",

End Selec

strFile = "select." & strEx

Response.Clea
Response.AddHeader "Content-disposition","attachment;filename=" & strFil

For row = 0 To lngNumRow

For col = 0 To lngNumCol

thisfld = arrData(col,row

If IsNull(thisfld) The

thisfld = strNul

End I

Response.Write(thisfld

If col < lngNumCols The

Response.Write(strSep

End I

Nex

Response.Write(vbCrLf

Nex

' Manually close the connectio
objConn.Clos
Set objConn = Nothin
Response.En

End I

----- Patrice wrote: ----

Youn can "Response.Write" the file content to the browser (strin
concatenation is still not recommended

Using
Response.Clea
Response.AddHeade
"Content-disposition","attachment;filename=basenameAAMMJJ.txt

Before sending the content will alow to raise the usual download dialog. Th
user will be able to save the file on his disk or to open the file (with th
program associated with the txt extension)

Patric

MDW said:
query a database and return the tables, columns, etc to a form that I ca
then use to build SQL statements to run against that database. It's ver
"generic" - i.e., everything is dymanically created but pretty handy t
havescreen showing your recordset. No big deal. What I'd also like to include i
some way for users to get that output in a comma- or tab-delimited text fil
that they can use however they like. There are two ways I know of t
accomplish thistrOutput & "'" & objRS(I) & "," .....) and then slap strOutput into
<textarea>. This is probably not desirable because the user would have t
believe that I'd have to SAVE the resultant file before I can send it t
users. I don't want to do thatif FSO is the way to go (which I suspect it is), bear in mind that my onl
exposure to FSO is in the context of .vbs files....are there any specia
tricks you need to use for ASP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top