ADO DOT NET Posted April 30, 2007 Posted April 30, 2007 hi how can i read all the contents of a text file (all the lines) and put it in a string? Quote
MrPaul Posted April 30, 2007 Posted April 30, 2007 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 :) Quote Never trouble another for what you can do for yourself.
Leaders snarfblam Posted April 30, 2007 Leaders Posted April 30, 2007 Re: StreamReader An easier way would be to use the ReadAllText method of the File class. [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) Quote [sIGPIC]e[/sIGPIC]
amir100 Posted May 2, 2007 Posted May 2, 2007 Re: StreamReader An easier way would be to use the ReadAllText method of the File class. [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". Quote Amir Syafrudin
Leaders snarfblam Posted May 3, 2007 Leaders Posted May 3, 2007 Re: StreamReader That is correct. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.