是否可以保存一个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/