Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

Generating HTML in C#

I have some C# code which looks something like this:
using (StreamWriter output = new StreamWriter(filename)
{
    output.Write("<HTML>");
    output.Write("<HEAD>...</HEAD>");
    output.Write("<BODY>");
    output.Write("<TABLE>");
    output.Write( table header stuff);

    // Now we output the HTML Table rows of data
    foreach(MyData data in myDataList)
    {
        output.Write("<tr><td>" + data.column1 + "</td><td>" + data.column2 + "</td><td>" + data.column3 + "</td></tr>");
    }

    output.Write("</TABLE>");
    output.Write("</BODY>");
    output.Write("</HTML>");
}

Open in new window

My question is, is there a better way of doing this? Can I somehow create a template, which looks like an HTML file, something like:
template = 
<HTML>
  <HEAD>
    ...
  </HEAD>
  <BODY>
    <TABLE>
      <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr>
      {magically fill in rows here from data}
    </TABLE>
  </BODY>
</HTML>

Open in new window

This looks nice, all except how would I get my C# code to "magically fill in rows here from data"?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial