Zechariah

help me please

how to read textfile to string



Re: Visual C# Express Edition how to read file to string

Brendan Grant

You can read an entire text file and put its contents into a string variable simply with:

string fileContents = System.IO.File.ReadAllText("SomeFile.txt");






Re: Visual C# Express Edition how to read file to string

Ashish Basran

Have a look at this, this should help you

http://msdn2.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx






Re: Visual C# Express Edition how to read file to string

Figo Fei - MSFT

Hi,

Simply use StreamReader can do this.

For example:

using (StreamReader sr = new StreamReader(@"C:/read.txt"))
            {
                string str = sr.ReadLine();
            }

In this way you can get the string in the file line by line or use sr.ReadToEnd() get all content in the file.

Otherwise, you can use fileStream, pls reference to: http://msdn2.microsoft.com/en-us/library/system.io.filestream.aspx

Thanks