Writing html files

  • Thread starter Thread starter guy
  • Start date Start date
G

guy

Does .NET have a class or set of functions that facilitate the creating and
writing of html files?

I have been creating files in streams and constructing html strings and
writing them out but it seems that a class could facilitate this better.

Thanks
 
Hi Guy,

HtmlTextWriter looks like it could help:

using System;
using System.IO;
using System.Text;
using System.Web.UI;

public class Test
{
public static void Main()
{
StringBuilder strBldr = new StringBuilder();
StringWriter strWriter = new StringWriter(strBldr);

HtmlTextWriter writer = new HtmlTextWriter(strWriter);

//<html>
writer.RenderBeginTag(HtmlTextWriterTag.Html);

// <head>
writer.RenderBeginTag(HtmlTextWriterTag.Head);

// </head>
writer.RenderEndTag();

// <body>
writer.RenderBeginTag(HtmlTextWriterTag.Body);

writer.Write("This is text for my web page.");

// </body>
writer.RenderEndTag();

// </html>
writer.RenderEndTag();

Console.WriteLine(strBldr.ToString());
}
}

Joe
 
Thanks.

Joe Mayo said:
Hi Guy,

HtmlTextWriter looks like it could help:

using System;
using System.IO;
using System.Text;
using System.Web.UI;

public class Test
{
public static void Main()
{
StringBuilder strBldr = new StringBuilder();
StringWriter strWriter = new StringWriter(strBldr);

HtmlTextWriter writer = new HtmlTextWriter(strWriter);

//<html>
writer.RenderBeginTag(HtmlTextWriterTag.Html);

// <head>
writer.RenderBeginTag(HtmlTextWriterTag.Head);

// </head>
writer.RenderEndTag();

// <body>
writer.RenderBeginTag(HtmlTextWriterTag.Body);

writer.Write("This is text for my web page.");

// </body>
writer.RenderEndTag();

// </html>
writer.RenderEndTag();

Console.WriteLine(strBldr.ToString());
}
}

Joe
 
It looks like you can only use HtmlTextWriter if you're writing an ASP.NET
app. This is just a normal windows forms app and I want to put some of my
result out in HTML format such that they can be loaded onto the net at a
later stage or view with a browser.
 
Back
Top