• Got a Tipila, google, windows live or facebook account ?

Use following methods to read a text file in c#

1.

    using (StreamReader sr = File.OpenText(FILE_NAME))
    {
        String input;
        while ((input = sr.ReadLine()) != null)
        {
            Console.WriteLine(input);
        }
        Console.WriteLine ("The end of the stream has been reached.");
    }

2

string text = System.IO.File.ReadAllText(@"C:\Users\Public\TestFolder\WriteText.txt");

3

string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Public\TestFolder\WriteLines2.txt");
1
votes
Hi...!!!

Tipila is a site for programmers to save interesting things found on the web, as Tips.

No more wasting time by re-googling for things you've found but forgotten.

It's totally free...
Get started now

Login to Tipila