有没有办法从ItemAttachment
的Item中删除HTML标记?
我只能从Item中获取文本。但不是来自ItemAttachment
的项目。
这是我的代码:
foreach (ItemAttachment itemAttach in item.Attachments.OfType<ItemAttachment>())
{
Console.WriteLine(itemAttach.Name);
itemAttach.Load();
PropertySet propSet = new PropertySet();
propSet.RequestedBodyType = BodyType.Text;
propSet.BasePropertySet = BasePropertySet.FirstClassProperties;
itemAttach.Item.Load(propSet);
Console.WriteLine(itemAttach.Item.Body.Text);
}
它将获得此异常
This operation isn't supported on attachments
我尝试使用商品ID绑定到Exchange服务。
它也给了我一些例外! 请给我一些建议。
答案 0 :(得分:0)
进,
您获得的例外与您正在创建的属性集有关。我没有看到您获取物品的代码,因此无法确定原因。我能够在我的机器上运行以下代码。您应该能够根据自己的需要进行修改。
// Return the first ten items.
ItemView view = new ItemView(10);
// Set the query string to only find emails with attachments.
string querystring = "HasAttachments:true Kind:email";
// Find the items in the Inbox.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, querystring, view);
// Loop through the results.
foreach (EmailMessage email in results)
{
// Load the email message with the attachments
email.Load(new PropertySet(EmailMessageSchema.Attachments));
// Loop through the attachments.
foreach (Attachment attachment in email.Attachments)
{
// Only process item attachments.
if (attachment is ItemAttachment)
{
ItemAttachment itemAttachment = attachment as ItemAttachment;
// Load the attachment.
itemAttachment.Load(new PropertySet(EmailMessageSchema.TextBody));
// Output the body.
Console.WriteLine(itemAttachment.Item.TextBody);
}
}
对于每个包含商品附件的电子邮件,我都可以看到删除了HTML标签的商品正文。
我希望这会有所帮助。如果这样可以解决您的问题,请将此帖标记为已回答。
谢谢,
---鲍勃---