【问题标题】:How to save ItemAttachments using EWS Managed API如何使用 EWS 托管 API 保存 ItemAttachments
【发布时间】:2013-02-01 11:48:23
【问题描述】:

是否可以保存ItemAttachment?对于FileAttachment,我们使用以下 EWS 托管 API 代码进行保存,

   if(attachment is FileAttachment)
    {
      FileAttachment fAttachment = new FileAttachment();
      fAttachment.Load("D:\\Stream" + fAttachment.Name);
    }

对于ItemAttachment呢?我们如何将ItemAttachment这样保存在指定文件中?

【问题讨论】:

  • 您使用什么版本的 Microsoft.Exchange.WebServices.dll?

标签: c# exchangewebservices ews-managed-api


【解决方案1】:

当然,这仍然不是一个紧迫的问题,但我想我会和我一样在未来偶然发现这个问题的人分享。

对于 ItemAttachments,您需要为该项目加载 MimeContent,然后您可以简单地写入文件/输出 [".eml", ".msg"]:

if (attachment is FileAttachment)
{
    FileAttachment fileAttachment = attachment as FileAttachment;

    // Load attachment contents into a file.
    fileAttachment.Load(<file path>);
}
else // Attachment is an ItemAttachment (Email)
{
    ItemAttachment itemAttachment = attachment as ItemAttachment;

    // Load Item with additionalProperties of MimeContent
    itemAttachment.Load(EmailMessageSchema.MimeContent);

    // MimeContent.Content will give you the byte[] for the ItemAttachment
    // Now all you have to do is write the byte[] to a file
    File.WriteAllBytes(<file path>, itemAttachment.Item.MimeContent.Content);
}

【讨论】:

  • 您使用什么版本的 Microsoft.Exchange.WebServices.dll?
  • 抱歉耽搁了。我正在使用 Microsoft EWS 托管 API 2.0:信息:msdn.microsoft.com/en-us/library/office/…> 库直接链接:microsoft.com/en-us/download/details.aspx?id=42022>
  • 没问题。这 itemAttachment.Load(EmailMessageSchema.MimeContent); 我一直都想念的东西。
  • 原因是:最初拉取项目时,它只抓取基础属性(或您建立的自定义属性集)。您想要的任何其他属性都必须按需加载。
猜你喜欢
  • 1970-01-01
  • 2012-03-20
  • 2017-05-04
  • 1970-01-01
  • 1970-01-01
  • 2013-08-25
  • 1970-01-01
  • 2014-10-15
  • 2023-03-23
相关资源
最近更新 更多