HtmlDocument的InnerHtml不变

时间:2019-07-11 12:21:21

标签: c# html-agility-pack

我正在尝试使用html敏捷包构建电子邮件模板。 我首先要获得基本布局:

public static HtmlDocument GetLayout()
        {
            string path = @"Modules\RoomBookingShared\Resources\EmailTemplate.html";
            HtmlDocument document = new HtmlDocument();
            document.Load(path);
            return document;
        }

使用创建的HtmlNode尝试将其写入Html中特定元素的内部。

        public static HtmlDocument SetBody(string body, HtmlDocument document)
        {
            string path = @"Modules\RoomBookingShared\Resources\test.html";
            HtmlDocument item = new HtmlDocument();
            item.Load(path);

            document.GetElementbyId("body-area").ChildNodes.Add(item.DocumentNode);
            FileStream sw = new FileStream("FileStream.html", FileMode.Create);
            document.Save(sw);
            return document;
        }

这不是设置,而是发送布局文件。奇怪的是,如果我写出文件(请参阅文件流代码),它将正确写出HTML文件。

应添加的输出(减去数据)如下:

<table cellspacing="0" cellpadding="0" border="0">    
    <tr>
        <td class="fallback-text maven" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; background-color: #343A40; border: 1px solid #454D55; color: white; text-align: center;">Location</td>
        <td class="fallback-text titillium" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; border: 1px solid #DEE2E6;"></td>
    </tr>
    <tr>
        <td class="fallback-text maven" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; background-color: #343A40; border: 1px solid #454D55; color: white; text-align: center;">Date & Time</td>
        <td class="fallback-text titillium" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; border: 1px solid #DEE2E6;"></td>
    </tr>
    <tr>
        <td class="fallback-text maven" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; background-color: #343A40; border: 1px solid #454D55; color: white; text-align: center;">Required </td>
        <td class="fallback-text titillium" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; border: 1px solid #DEE2E6;"></td>
    </tr>
    <tr>
        <td class="fallback-text maven" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; background-color: #343A40; border: 1px solid #454D55; color: white; text-align: center;">Attendees</td>
        <td class="fallback-text titillium" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; border: 1px solid #DEE2E6;"></td>
    </tr>
    <tr>
        <td class="fallback-text maven" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; background-color: #343A40; border: 1px solid #454D55; color: white; text-align: center;">Booking Reason</td>
        <td class="fallback-text titillium" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; border: 1px solid #DEE2E6;"></td>
    </tr>
    <tr>
        <td class="fallback-text maven" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; background-color: #343A40; border: 1px solid #454D55; color: white; text-align: center;">Reference</td>
        <td class="fallback-text titillium" style="padding: 10px 25px 10px 25px; mso-height-rule: exactly; border: 1px solid #DEE2E6;"></td>
    </tr>
</table>

任何人都可以看到我在做什么吗?

1 个答案:

答案 0 :(得分:0)

问题似乎与ParsedText和Text有关。 要解决此问题,我必须使用以下内容:

Body = final.DocumentNode.OuterHtml;