1 Attachment(s)
Reading a text file using C#
Hi,
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:
Quote:
Index and Length must refer to a location within the string.
Does anybody know what I am doing wrong?
Thanks in advance,
DJ