Temporary txt,csv Files?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MDW

    Temporary txt,csv Files?

    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

  • Patrice

    #2
    Re: Temporary txt,csv Files?

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

    Using :
    Response.Clear
    Response.AddHea der
    "Content-disposition","a ttachment;filen ame=basenameAAM MJJ.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" <anonymous@disc ussions.microso ft.com> a écrit dans le message de
    news:846E3D26-F635-419C-8F3D-54B9EE0F0958@mi crosoft.com...[color=blue]
    > Hey all,
    >
    > I've got a web-based "database admin console" that uses ADOX, etc. to[/color]
    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.[color=blue]
    >
    > If you send it a "SELECT" statement, it can print out a table on the[/color]
    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[color=blue]
    >
    > 1) Create a big string as I step through the recordset - (strOutput =[/color]
    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.[color=blue]
    >
    > 2) Use the FSO. However, my limited experience with the FSO leads me to[/color]
    believe that I'd have to SAVE the resultant file before I can send it to
    users. I don't want to do that.[color=blue]
    >
    > Does anyone have any suggestions about how else I can accomplish this? Or,[/color]
    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?[color=blue]
    >
    > TIA.
    >[/color]


    Comment

    • MDW

      #3
      Re: Temporary txt,csv Files?

      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("S ave") <> "" Then ' The user wants to save the recordse

      strExt = Request.Form("S ave"

      Select Case UCase(strExt

      Case "TXT

      strSep = vbTa

      Case "CSV

      strSep = ",

      End Selec

      strFile = "select." & strEx

      Response.Clea
      Response.AddHea der "Content-disposition","a ttachment;filen ame=" & 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.AddHea de
      "Content-disposition","a ttachment;filen ame=basenameAAM MJJ.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" <anonymous@disc ussions.microso ft.com> a écrit dans le message d
      news:846E3D26-F635-419C-8F3D-54B9EE0F0958@mi crosoft.com..[color=blue]
      > Hey all[color=green]
      >> I've got a web-based "database admin console" that uses ADOX, etc. t[/color][/color]
      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
      have[color=blue][color=green]
      >> If you send it a "SELECT" statement, it can print out a table on th[/color][/color]
      screen 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 thi[color=blue][color=green]
      >> 1) Create a big string as I step through the recordset - (strOutput[/color][/color]
      strOutput & "'" & objRS(I) & "," .....) and then slap strOutput into
      <textarea>. This is probably not desirable because the user would have t
      copy all the content in that <textarea> and manually paste it into Notepa
      or whatever[color=blue][color=green]
      >> 2) Use the FSO. However, my limited experience with the FSO leads me t[/color][/color]
      believe that I'd have to SAVE the resultant file before I can send it t
      users. I don't want to do that[color=blue][color=green]
      >> Does anyone have any suggestions about how else I can accomplish this? Or[/color][/color]
      if 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[color=blue][color=green]
      >> TIA[/color]
      >[/color]

      Comment

      • MDW

        #4
        Re: Temporary txt,csv Files?

        Nevermind - I got it figured out. Response.Conten tType = "text/plain"

        Comment

        Working...