Read text file into string

Does anyone know how to read a text file (.txt) into a string variable using VB.NET and VS.NET 2003

Thanks




Answer this question

Read text file into string

  • sunrunner

    Do IO objects require any Excel VBA Tools/References other than the normal ones to work My Excel 2003 VBA doesn't seem to like that statement.


  • Susan S

    .NET will not work in VBA



  • rbroadbent

    Thank you for the reply. It worked with the exception that my txt file was too long. Is there any way to read an extremely long text file or create an array of the pieces of the text file

  • Kamarey

    too long wow...the string type is capable of handling aprox 2 billion characters...but yes you can read portions using readline or readblock instead of readtoend

  • Poh Tham

    Dim s As String

    Dim tr As IO.TextReader = New IO.StreamReader("C:\MyTextFile.txt")

    s = tr.ReadToEnd



  • Read text file into string