I need to be able to pass HTML data into Outlook like this:
MailMessage message = new MailMessage();
message.Body = myBody;
Initially, I th
This is my version of it, with added the possibility to "highlight" some rows based on a generic rule (rowHighlightRule parameter).
public static string ToHTML(this DataTable dt, Func rowHiglithRule)
{
if (dt == null) throw new ArgumentNullException("dt");
string tab = "\t";
StringBuilder sb = new StringBuilder();
sb.AppendLine(tab + tab + "");
// headers.
sb.Append(tab + tab + tab + "");
foreach (DataColumn dc in dt.Columns)
{
sb.AppendFormat("{0} ", dc.ColumnName);
}
sb.AppendLine(" ");
// data rows
foreach (DataRow dr in dt.Rows)
{
if (rowHiglithRule != null)
{
if (rowHiglithRule(dr))
{
sb.Append(tab + tab + tab + "");
}
else
{
sb.Append(tab + tab + tab + " ");
}
}
else
{
//Non ho alcuna regola, quindi caso normale.
sb.Append(tab + tab + tab + " ");
}
foreach (DataColumn dc in dt.Columns)
{
string cellValue = dr[dc] != null ? dr[dc].ToString() : "";
sb.AppendFormat("{0} ", cellValue);
}
sb.AppendLine(" ");
}
sb.AppendLine(tab + tab + "
");
return sb.ToString();
}