Read Text File in Rich Text Box

Posted on 2004-11-30
Last Modified: 2008-03-17
How would I go about reading a text file, say "c:\test.txt" into a rich text box on a form?  
Question by:fattumsdad
    1 Comment
    LVL 3

    Accepted Solution


    Say you have a form of type Form1 (what a surprise !) and a richTexBox1 (gosh that's great).

    You can put, in the load event (just dbl click on your form in the designer:

    using(System.IO.StreamReader l_reader = new System.IO.StreamReader(@"c:\test.txt"))
       richTextBox1.Text = l_reader.ReadToEnd();

    This does the trick.

    If you want formatting or something more powerfull, it may be different, but for simple text, this is all you need.


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now