1

I have a string that has HTML formatted content.

Now I want to convert that string to HTML, May I use HtmlElementCollection

Is it possible? If yes, then how?

Kindly explain. Thanks!

Ahsan Khurshid
  • 9,383
  • 1
  • 33
  • 51
Alkis
  • 57
  • 1
  • 1
  • 6
  • 2
    `a string that has HTML formatted content` is an html – L.B Sep 10 '12 at 12:59
  • But how i can use it as html? for example my string have etc... How I can use HtmlElementCollection on it? – Alkis Sep 10 '12 at 13:09
  • I don't think you can get from a string to an HtmlElementCollection. An instance of the HtmlElementCollection can only be created through the HtmlDocument, which can only be set from the Document property of the WebBrower control (see http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.aspx for additional information about this. I think what you want to use is the HtmlAgilityPack (see Dan Lister's answer below) – Gene S Sep 10 '12 at 13:25

4 Answers4

1

Take a look at the HtmlAgilityPack. More information can be found on the answers of other similar questions.

Community
  • 1
  • 1
Dan Lister
  • 2,543
  • 1
  • 21
  • 36
1

A string will be handled as HTML when you push this string into an environment that will render the content as HTML.

When you push the content of the string to an environment that doesn't handle HTML or you explicitly say that you don't want it to render as HTML. It will be rendered as plain text.

cherry3
  • 79
  • 7
0

Use HTMLAGILITYPACK and use the following:

var st1 = stringdata; // your html formatted string
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(st1); // this is now html doc
Toni
  • 1,555
  • 4
  • 15
  • 23
ahamed
  • 23
  • 5
0

If someone still locking for this

For that just type code below in the place you what to show the HTML

@((MarkupString)htmlString)

//htmlString =>string that has HTML formatted content

//tested with blazor server last ver of dotnet(now 6.0)

Game dev
  • 296
  • 2
  • 17