问题
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