gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:13:33 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

对于 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);
}

关于c# - 如何使用 EWS 托管 API 保存项目附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14645643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com