Technofyed

Full Version: Reading text file using c#
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using c# console application, how can I read text file line by line using c#, any help regarding this is appreciated
I have one code that you can use this code into your Main method for a console window.
This sample requires some form of a text (.txt) file from which to read.
int counter = 0;
string line;
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
}
file.Close();
Console.ReadLine();
For reading line by line of richtextbox use the bellow code that may help you

foreach (string line in richTextBox1.Lines)
{
label1.Text = label1.Text.ToString() + line + Environment.NewLine;
}

I think it will be work.
Reference URL's