Create HTML webpage programmatically in C#

c#, html

Solution

You could use NVelocity. It is a .Net port of the Java Velocity templating system. The API will not be similar to XmlWriter. Instead, you'll write a text file in a simple scripting language, put your objects into a 'context' and then merge the template and the context to generate the HTML file.

NVelocity

Problem

I was wondering: is there a way to create HTML files programmatically in C# as you can do with XML? Mine is a console application, so maybe some of the options are not available. Basically, I would like to do something smarter than just building a big string. Possible scenario: Instead of writing: ``` string html="<html><head>Blah</head><body>{0}</html>", myotherstring ``` I would like to work as in XML ``` XmlTextWriter w = new XmlTextWriter(xml_file_path + xml_file_name, System.Text.Encoding.UTF8); w.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); // construct xml XmlElement root = xmlDoc.CreateElement("element"); ... xmlDoc.Save(w); w.Close(); ``` Apologies for the naive question.

Original source