item.HasAttachments is true but no attachments in collection

…衆ロ難τιáo~ 提交于 2019-12-22 10:18:47

问题


I need to retrieve & copy attached files from a number of mail items. Problem is each mail item's collection is empty, even though the property HasAttachment is true.

Do I need to load each mail item's attachment colloection somehow after the mail item is retrieved?

The following code spits out the exception "index is out of range.":

FindItemsResults<Item> findResults = service.FindItems(
                WellKnownFolderName.Inbox,
                new ItemView(1));

foreach (Item item in findResults.Items)
{
    if (item.HasAttachments && item.Attachments[0] is FileAttachment)
    {
         //Do stuff
    }
}

回答1:


Fell upon the solution; item.Load(). I guess it's logical since a light application might not be interested in collecting heavy attachments when not needed.



来源:https://stackoverflow.com/questions/12954284/item-hasattachments-is-true-but-no-attachments-in-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!