[英]How to move ItemAttachments to a Folder using EWS managed API 2
[英]How to save ItemAttachments using EWS Managed API
是否可以保存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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.