How do I convert an string containing HTML to RichText Format using .Net/C# in VS 2010.

Posted on 2011-10-19
Last Modified: 2012-05-12

I'm building a winform app using VS2010 and C#.

I will be receiving "blocks" of HTML, which I would in turn like to translate to Rich Text Format
and display within a RichText control. I assume that this is the best approach for displaying
the data with my app.

Is there an easy way to do this? Are there any open source solutions available out there?

The default thing to do would be to convert this to straight text and display it within a multi-line
text box. I would rather end up with Rich Text. But, if this is not possible, then I'd settle for straight text.
Is there an easy way to convert HTML to Text?

Question by:jxbma
    LVL 82

    Expert Comment

    by:Dave Baldwin
    Check to see if your "Rich Text Format" isn't HTML anyway.  The old version of RTF used to be a file format but a lot of recent things use HTML as "Rich Text Format".

    Expert Comment

    How about using XHTML ,then you can treat the document as being an XML document
    and parse and display as you like.

    Alternatively use the Apple WEBKIT located here, most browsers today use this, (will need C++) for this.


    Your best bet would be to EMBED Internet Explorer within your application:
    Try this out:

    Good Luck.
    LVL 1

    Author Comment


    If possible, I would to avoid using a web browser for this if possible.
    (Is that the easiest method?) Is it as simple as embedding the control,
    and setting the content to my hmtl?

    Can you speak more to using XHTML to accomplish this?
    Is this a major deal to implement?

    LVL 14

    Accepted Solution


    Expert Comment


    Parsing HTML is hard, as there can be errors in the document. Browsers will be able to deal
    with this type of document as most browsers are intelligent enough even if the document contain errors.

    XHTML on the other-hand is different, NO ERRORS allowed, almost like XML. You will have to parse
    the document and decide how and what tags you want to display.

    Even if you do find a Control that can render and display a web page, you will have a higher success rate when using (Internet Explorer) as a Control. But this is limited as you might have guessed to certain platforms. And the version of IE also plays a roll.

    Hope that helps.


    LVL 1

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now