Read Text File


//Reading Text Files

//Use the using directive
using System.IO;

//With Text Reader

TextReader tr = File.OpenText(@"C:\yourFile.txt");

string fileContent = tr.ReadToEnd();

tr.Close();

//With Stream Reader

StreamReader sr = new StreamReader(@"C:\yourFile.txt");

StringBuilder fileContent = new StringBuilder();

string input;

while ((input = sr.ReadLine()) != null)

fileContent.AppendLine(input);

sr.Close();


You can view this article online at:
http://www.kiranreddys.com/knowledgebase/index.php/article/read-text-file