print from txt file

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

    print from txt file

    Hi,

    Ok, last question of the day!

    Can I have the contents of a *.txt file simply being printed on a page
    (presumably by using response.write) ?

    Many thanks for all your help today,
    Oli


  • Ray at

    #2
    Re: print from txt file

    Not ~printed~ since that would be something the user would have to do, but
    if you mean displayed in the page, you can <!-- #include
    file="yourfile. txt" --> it or Server.Execute "file.txt" it.

    Those are two options.

    Ray at work

    "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
    news:bqlar0$253 $1@sparta.btint ernet.com...[color=blue]
    > Hi,
    >
    > Ok, last question of the day!
    >
    > Can I have the contents of a *.txt file simply being printed on a page
    > (presumably by using response.write) ?
    >
    > Many thanks for all your help today,
    > Oli
    >
    >[/color]


    Comment

    • Aaron Bertrand - MVP

      #3
      Re: print from txt file

      Also, you could use Scripting.FileS ystemObject to open the file and read it
      (e.g. if you wanted to parse the contents, or only show certain lines, etc.)

      --
      Aaron Bertrand
      SQL Server MVP
      Please contact this domain's administrator as their DNS Made Easy services have expired.





      "Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
      news:#p4du6cuDH A.1740@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Not ~printed~ since that would be something the user would have to do, but
      > if you mean displayed in the page, you can <!-- #include
      > file="yourfile. txt" --> it or Server.Execute "file.txt" it.
      >
      > Those are two options.
      >
      > Ray at work
      >
      > "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
      > news:bqlar0$253 $1@sparta.btint ernet.com...[color=green]
      > > Hi,
      > >
      > > Ok, last question of the day!
      > >
      > > Can I have the contents of a *.txt file simply being printed on a page
      > > (presumably by using response.write) ?
      > >
      > > Many thanks for all your help today,
      > > Oli
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Bhaskardeep Khaund

        #4
        Re: print from txt file

        Hi,

        You can do this...

        Set myObject = Server.CreateOb ject("Scripting .FileSystemObje ct")
        Set myTextFile = myObject.OpenTe xtFile(Server.M apPath("../../textfile.txt"))
        While not myTextFile.AtEn dOfStream
        Response.Write( myTextFile.Read Line & "<br>")
        Wend
        myTextFile.Clos e


        Regards,
        Bhaskardeep Khaund

        Comment

        • Aaron Bertrand - MVP

          #5
          Re: print from txt file

          > While not myTextFile.AtEn dOfStream[color=blue]
          > Response.Write( myTextFile.Read Line & "<br>")[/color]

          Ugh... a loop? Why? How about:

          Response.Write Replace(myTextF ile.ReadAll(), vbCrLf, "<br>")

          --
          Aaron Bertrand
          SQL Server MVP
          Please contact this domain's administrator as their DNS Made Easy services have expired.





          Wend
          myTextFile.Clos e


          Regards,
          Bhaskardeep Khaund


          Comment

          • Ray at

            #6
            Re: print from txt file

            Why go line by line? Just readall and replace vbCrLfs with <br>s or use the
            <pre> tag.

            Ray at work


            "Bhaskardee p Khaund" in an HTML message:

            You can do this...

            Set myObject = Server.CreateOb ject("Scripting .FileSystemObje ct")
            Set myTextFile = myObject.OpenTe xtFile(Server.M apPath("../../textfile.txt"))
            While not myTextFile.AtEn dOfStream
            Response.Write( myTextFile.Read Line & "<br>")
            Wend
            myTextFile.Clos e


            Regards,
            Bhaskardeep Khaund


            Comment

            • Bhaskardeep Khaund

              #7
              Re: print from txt file

              Hi,

              I have used the loot because, if the content of the text file is too big it would be an extra strain on the server. And when using the loops u could format each sentence, leading to more flexibility. I think its a matter of coding style. Whats say?

              Bhaskardeep Khaund

              Comment

              • Aaron Bertrand [MVP]

                #8
                Re: print from txt file

                Please post in plain text. These HTML attachments are annoying, and so is
                having to switch from HTML mode when replying. I think we just found #5007!


                Comment

                • Ray at

                  #9
                  Re: print from txt file


                  "Aaron Bertrand [MVP]" <aaron@TRASHasp faq.com> wrote in message
                  news:uYjrmxuuDH A.1760@TK2MSFTN GP10.phx.gbl...[color=blue]
                  > Please post in plain text. I think we just found #5007![/color]

                  DO IT!


                  Comment

                  • William Tasso

                    #10
                    Re: print from txt file

                    Aaron Bertrand [MVP] wrote:[color=blue]
                    > Please post in plain text. These HTML attachments are annoying, and
                    > so is having to switch from HTML mode when replying. I think we just
                    > found #5007![/color]

                    LOL - good call.

                    --
                    William Tasso - http://WilliamTasso.com


                    Comment

                    Working...