Exchange EWS MailItem显示附件,但不允许我检索文件附件

时间:2012-08-07 23:22:48

标签: exchangewebservices

我正在尝试从交换电子邮件中加载文件附件(图像文件)。

` foreach(findResults.Items中的EmailMessage项)             {                 if(item.HasAttachments)                 {                     var something = item.Attachments [0];

                foreach (Attachment attachment in item.Attachments)
                {
                    if (attachment is FileAttachment)
                    {
                        FileAttachment fattach = (FileAttachment)attachment;`

出于某种原因,即使该项目有附件(我可以通过登录Web界面确认这一点),它也不允许我检索文件附件。

它显示为null。为什么一个项目在集合中有附件但是没有它可以检索?

3 个答案:

答案 0 :(得分:0)

我遇到类似的问题,并非所有属性都已设置,因此您需要从Exchange服务本身调用LoadPropertiesForItems方法来加载附件等额外数据。
例如,如果要加载项x的所有附件,则交换服务实例为s:

List<Item> xlist = new List<Item>();
            xlist.Add(x);
            s.LoadPropertiesForItems(xlist,PropertySet.FirstClassProperties);

答案 1 :(得分:0)

绑定到Item时,需要指定Attachments属性。以下代码示例应该有所帮助:

PropertySet propertySet = new PropertySet(ItemSchema.Subject, ItemSchema.Attachments);    
Item item = Item.Bind(service, itemId, propertySet);

答案 2 :(得分:0)

您错过了加载附件。请参阅以下示例了解

EmailMessage msgInfo = null;
foreach (Item msgItemInfo in msgItemWithNotification)
{
   msgInfo = EmailMessage.Bind(exchange, msgItemInfo.Id);
   foreach (Attachment attachment in msgInfo.Attachments)
       {
           if( attachment is FileAttachment)
              {
                  FileAttachment fattach = attachment as MSEWS.FileAttachment;
                  fattach.Load();
                  Stream excelFileStream = new System.IO.MemoryStream(fattach.Content);
              }
       }
}