• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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


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?

1 Solution
Dave BaldwinFixer of ProblemsCommented:
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".
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,
http://www.webkit.org/ (will need C++) for this.


Your best bet would be to EMBED Internet Explorer within your application:
Try this out: http://www.codeproject.com/KB/dotnet/DesktopWidget.aspx

Good Luck.
jxbmaSoftware ConsultantAuthor Commented:

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?

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

nishant joshiTechnology Development ConsultantCommented:

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.


jxbmaSoftware ConsultantAuthor Commented:

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now