Skalis
Skalis

Reputation: 197

item.HasAttachments is true but no attachments in collection

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
    }
}

Upvotes: 3

Views: 1738

Answers (1)

Skalis
Skalis

Reputation: 197

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.

Upvotes: 6

Related Questions