C# and writing HTML - best way?

877 views Asked by At

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

2

There are 2 answers

0
AldenHurley On BEST ANSWER

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>
2
Pavel Minaev On

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).