首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用EWS Managed API保存ItemAttachments

如何使用EWS Managed API保存ItemAttachments
EN

Stack Overflow用户
提问于 2013-02-01 19:48:24
回答 1查看 6.7K关注 0票数 7

可以保存ItemAttachment吗?对于FileAttachment,我们使用以下EWS管理的API代码来保存,

代码语言:javascript
复制
   if(attachment is FileAttachment)
    {
      FileAttachment fAttachment = new FileAttachment();
      fAttachment.Load("D:\\Stream" + fAttachment.Name);
    }

那么对于ItemAttachment呢?我们如何将这样的ItemAttachment保存到指定的文件中?

EN

回答 1

Stack Overflow用户

发布于 2014-01-22 01:06:31

当然,这不是一个紧迫的问题,但我想我会分享给任何人谁在未来偶然发现这一点,就像我所做的。

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

代码语言:javascript
复制
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);
}
票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14645643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档