read text file

StreamReader

Use the System.IO.StreamReader class. It has a constructor which takes a filename and has a ReadToEnd() method which will return the entire contents of the file in a string.

Good luck :)
 
Re: StreamReader

An easier way would be to use the ReadAllText method of the File class.
Code:
[COLOR="Magenta"]C#[/COLOR]
[COLOR="Blue"]string[/COLOR] text = System.IO.File.ReadAllText(filename);

[COLOR="Magenta"]VB[/COLOR]
[COLOR="Blue"]Dim [/COLOR]Text [COLOR="Blue"]As String [/COLOR]= System.IO.File.ReadAllText(Filename)
 
Re: StreamReader

An easier way would be to use the ReadAllText method of the File class.
Code:
[COLOR="Magenta"]C#[/COLOR]
[COLOR="Blue"]string[/COLOR] text = System.IO.File.ReadAllText(filename);

[COLOR="Magenta"]VB[/COLOR]
[COLOR="Blue"]Dim [/COLOR]Text [COLOR="Blue"]As String [/COLOR]= System.IO.File.ReadAllText(Filename)

This is (as quoted from MSDN) "new in the .NET Framework version 2.0".
 
Back
Top