Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除EWS电子邮件正文中的HTML部分_C#_Html_Css_Exchangewebservices - Fatal编程技术网

C# 删除EWS电子邮件正文中的HTML部分

C# 删除EWS电子邮件正文中的HTML部分,c#,html,css,exchangewebservices,C#,Html,Css,Exchangewebservices,在通过C#中的ResponseMessage回复之前,我想删除HTMLEWS EmailMessage.Body.Text值的一部分内容 要删除的内容如下所示,它们包含可单击和不可剪裁的html按钮 我发现我们无法声明自己的自定义标记,因此我无法使用string。通过查找自定义html标记替换 我可以知道我的任务是否有变通方法,例如将下面的内容放在占位符中等吗 <table class="MsoNormalTable" border="0" cellspacing="0" cellpadd

在通过
C#
中的
ResponseMessage
回复之前,我想删除
HTML
EWS EmailMessage
.Body.Text
值的一部分内容

要删除的内容如下所示,它们包含可单击和不可剪裁的
html
按钮

我发现我们无法声明自己的自定义标记,因此我无法使用
string。通过查找自定义html标记替换

我可以知道我的任务是否有变通方法,例如将下面的内容放在占位符中等吗

<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100.0%">
<tbody>
<tr>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="30%" style="width:30.0%;background:#17202A;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white">ACTION: ADD
<o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="30%" style="width:30.0%;background:#17202A;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white">ACTION: MINUS
<o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="20%" style="width:20.0%;background:#3A69C2;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white"><a href="mailto:test.com?subject=[MULTIPLY];body=ACTION:%20MULTIPLY"><span style="color:white;background:#3A69C2;text-decoration:none">MULTIPLY
</span></a><o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
<td width="20%" style="width:20.0%;background:#3A69C2;padding:4.5pt 4.5pt 4.5pt 4.5pt;display:inline-block">
<p class="MsoNormal" align="center" style="text-align:center"><b><span style="font-size:11.5pt;font-family:&quot;Helvetica&quot;,sans-serif;color:white"><a href="mailto:test.com?subject=[DIVIDE];body=ACTION:%20DIVIDE"><span style="color:white;background:#3A69C2;text-decoration:none">DIVIDE
</span></a><o:p></o:p></span></b></p>
</td>
<td style="padding:0in 0in 0in 0in">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,serif">&nbsp;<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>

操作:添加

操作:减号


您是否可以使用html标记的Id属性来标识要删除的标记?

您是否可以使用html标记的Id属性来标识要删除的标记?

假设您要删除包含乘法和除法按钮的表,并且在列表中的其他任何位置都找不到它们文档我们可以将它们与XPath结合使用来查找表并将其删除。您可以使用inbuild
XMLDocument
类,但由于它是HTML,我建议使用(作为nuget包提供)来解析HTML

你最终会得到这样的结果:

//Create a HTMLAgilityPack Document
HtmlDocument doc = new HtmlDocument();
//Load the email body
doc.LoadHtml(EmailMessage.Body.Text);
//Select the ancestor table of the link we're interested in
HtmlNode node = doc.DocumentNode.SelectSingleNode("//a[@href='mailto:test.com?subject=[DIVIDE];body=ACTION:%20DIVIDE']//ancestor::table");
//Remove the table
node.Remove();

//Get the new email body
string newBody = doc.DocumentNode.InnerHtml;

您可能需要稍作调整才能到达目的地,但希望这是一个良好的开端。

假设您希望删除包含乘法和除法按钮的表,并且在文档中的其他任何地方都找不到它们,我们可以将它们与XPath结合使用来查找并删除该表。您可以使用inbuild
XMLDocument
类,但由于它是HTML,我建议使用(作为nuget包提供)来解析HTML

你最终会得到这样的结果:

//Create a HTMLAgilityPack Document
HtmlDocument doc = new HtmlDocument();
//Load the email body
doc.LoadHtml(EmailMessage.Body.Text);
//Select the ancestor table of the link we're interested in
HtmlNode node = doc.DocumentNode.SelectSingleNode("//a[@href='mailto:test.com?subject=[DIVIDE];body=ACTION:%20DIVIDE']//ancestor::table");
//Remove the table
node.Remove();

//Get the new email body
string newBody = doc.DocumentNode.InnerHtml;

您可能需要稍微调整一下才能到达目的地,但希望这是一个好的开始。

我已经尝试了
标题
表格
ID
属性。但是,在获取电子邮件正文内容后,找不到
ID
信息,只显示
summary
属性。因此,我最终使用了带有空
表的
summary
属性,直到找到了更好的解决方案。我尝试了
标题
ID
属性。但是,在获取电子邮件正文内容后,找不到
ID
信息,只显示
summary
属性。因此,我最终使用了带有空
表的
summary
属性,直到找到更好的解决方案。谢谢@Jon,我会尝试一下。由于它们不是可单击的按钮,因此这对添加和减去也有效吗?这将删除父表。。。你到底想删除什么。也许可以编辑您的问题以包含所需的输出。谢谢@Jon,我将尝试一下。由于它们不是可单击的按钮,因此这对添加和减去也有效吗?这将删除父表。。。你到底想删除什么。也许可以编辑您的问题以包含所需的输出。