I may be completely stupid but I can't make the code below work?! The text file TEST.TXT is a one liner (attached) and it is still not working!!!!! Please can somebody help me...... this was copied straight from MSDN...
Code:
using (StreamReader sr = new StreamReader("c:\\TEST.TXT"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
tb.AppendText(line + Environment.NewLine);
}
}
I receive the error as follows:
Index and Length must refer to a location within the string.
I agree--the code looks good. I threw this into a console application and instead of using a control, threw the read text into a StringBuilder object:
Code:
using System;
using System.Text;
using System.IO;
class test
{
public static void Main()
{
StringBuilder tb = new StringBuilder();
using (StreamReader sr = new StreamReader("c:\\TEST.TXT"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
tb.Append(line + Environment.NewLine);
}
}
Console.WriteLine(tb);
}