如何使用 EWS 托管 API 保存项目附件

本文关键字:项目 保存 API 何使用 EWS 托管 | 更新日期: 2023-09-27 17:56:54

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

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

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

如何使用 EWS 托管 API 保存项目附件

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

对于项目附件,您需要加载项目的 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);
}