Search code examples
c#winformsrichtextboxstreamreader

C# Read several lines with StreamReader?


I'm new to C# and I have a problem. I would like to have the content of a file written to a RichTextBox, but the StreamReader.ReadLine method reads only the first line.

How can I solve this?


Solution

  • Probably the easiest way to do this would be to use the System.IO.File class's ReadAllText method:

    myRichTextBox.Text = File.ReadAllText(filePath);
    

    This class has a bunch of static methods that wrap the StreamReader class for you that make reading and writing to files quite easy.