views:

157

answers:

2

Hi, I would need to build a HTML document from plain text and display it in webBrowser. I was thinking of better way - I can see there is HTMLTextWriter in System.Web.UI but I cannot reference this namespace, could anyone advice? Thanks

+1  A: 

Simplest way is to use plain XmlWriter (or, if you need more complex building than just writing a stream of elements, XmlDocument or XDocument) and output XHTML.

If you want to use System.Web.UI classes, you need to reference System.Web.dll from your project. I wouldn't recommend it, though, as it won't buy you much, and it is not included in the .NET Client Profile (which you might want to use in the future, especially with .NET 4).

Pavel Minaev
Thanks! Is that capable of writing html header etc.?
Petr
What do you mean by HTML header? If `<head>`, then it is an XHTML element like any other, and, naturally, can be written easily.
Pavel Minaev
+1  A: 

Depending on your application requirements you could host your own browser control and build the content:

System.Windows.Forms.WebBrowser _browser = new WebBrowser();
_browser.DocumentText = "<html><head><title>My Web Page</title></head><body>Hello World!</body></html>
AldenHurley
Excellent idea! Thanks
Petr