-1

I am showing email message body in textbox which is containing html tags in it and showing all tags as it but i want to render it and show actual formatted text. The message body is a string type but was originally a html document sent in email.

Output I am getting:

enter image description here

What I want:

enter image description here

When I use:

 body = System.Net.WebUtility.HtmlEncode(body);
 TxtBodyText.Text = body;

Then it converts < and > to &lt, &gt etc but i wanna display formatted text. Also tried HtmlAgilityPack's Entitize method but no success. Is it possible to do so?

Please help!!

Preet
  • 984
  • 2
  • 14
  • 34
  • Why is it rendered in a textbox ? Does it have to be editable ? If yes you need to use some rich text editing component – klugjo Nov 29 '17 at 03:04
  • @klugjo not editing at the moment but planning to do in future. – Preet Nov 29 '17 at 03:08
  • 1
    Editing HTML as if it was just a bunch of text with some styles is a very complex subject. I suggest you find yourself a wysiwyg editor of some sort and use that in your project – klugjo Nov 29 '17 at 03:12
  • take a look here for inspiration: https://stackoverflow.com/questions/731649/how-can-i-convert-html-to-text-in-c – Kevin Avignon Nov 29 '17 at 03:12
  • @klugjo and Kevin thanks you both for help will try these suggestions – Preet Nov 29 '17 at 03:17

1 Answers1

1

You can't render HTML content inside a text box or text area. You need to use a div or an editable div.

Below is an example-

<div contenteditable="true">
    Hi <b>Cheryl</b>,<br/><br/><br/>
    Thank you for your order. Your project ID is C00031. Your invoice is attached.
</div>

Here's a demo: http://jsfiddle.net/XNkDx/7225/

Souvik Ghosh
  • 4,456
  • 13
  • 56
  • 78