Creating HTML from a DataTable using C#

后端 未结 9 1507
盖世英雄少女心
盖世英雄少女心 2020-12-30 11:37

I need to be able to pass HTML data into Outlook like this:

MailMessage message = new MailMessage();
message.Body = myBody;

Initially, I th

9条回答
  •  渐次进展
    2020-12-30 12:26

    There are a number of ways to output the HTML.

    If this is a relatively easy format (not much formatting, styles etc.) I would definitely go with @mservidio's suggestion.

    If the output is more complex and you have experience with ASP.NET you can go the route of a UserControl which allows more flexibility and management of the output. You can then render the output of the control to HTML like this:

    StringBuilder sb = new StringBuilder();
    StringWriter tw = new StringWriter(sb);
    HtmlTextWriter hw = new HtmlTextWriter(tw);
    
    ctrl.RenderControl(hw);
    return sb.ToString();
    

提交回复
热议问题