Results 1 to 3 of 3

Thread: Reading a text file using C#

Threaded View

  1. #1

    Thread Starter
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159

    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:
    Index and Length must refer to a location within the string.
    Does anybody know what I am doing wrong?

    Thanks in advance,
    DJ
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width