How do we show the pictures of the requried and optional attendees in an appointment? According to the documentation it should be possible retrive the photos with this method (MSDN):
private static void GetContactPhoto(ExchangeService service, string ItemId)
{
// Bind to an existing contact by using the ItemId passed into this function.
Contact contact = Contact.Bind(service, ItemId);
// Load the contact to get access to the collection of attachments.
contact.Load(new PropertySet(ContactSchema.Attachments));
// Loop through the attachments looking for a contact photo.
foreach (Attachment attachment in contact.Attachments)
{
if ((attachment as FileAttachment).IsContactPhoto)
{
// Load the attachment to access the content.
attachment.Load();
}
}
FileAttachment photo = contact.GetContactPictureAttachment();
// Create a file stream and save the contact photo to your computer.
using (FileStream file = new FileStream(photo.Name, FileMode.Create, System.IO.FileAccess.Write))
{
photo.Load(file);
}
}
But when loading an appointment object the RequiredAttendees and OptionalAttendees arrays only returns EmailAdress object. How can the EmailAdress be converted into an ItemId so that the GetContactsPhoto method in the documentation can be used?
//Print out to se what we get.
foreach (Microsoft.Exchange.WebServices.Data.Appointment a in appointments)
{
a.Load(_customPropertySet);
//Required, Optional, Resource
// Check responses from required attendees.
for (int i = 0; i < a.RequiredAttendees.Count; i++)
{
Console.WriteLine("Required attendee - " + a.RequiredAttendees[i].Address);
}
The customPropertySet looks like this:
//Configure so that the body of an appointment is readable.
PropertySet _customPropertySet = new PropertySet(BasePropertySet.FirstClassProperties,
AppointmentSchema.MyResponseType,
AppointmentSchema.IsMeeting,
AppointmentSchema.ICalUid,
AppointmentSchema.RequiredAttendees,
AppointmentSchema.OptionalAttendees,
AppointmentSchema.Resources);
Tried passing the email address as Id but that returns an error message saying that the "id is malformed".
Update 1: Tried using Resolve method as pointed out in the answer by Jason Johnson. He correctly pointed out and I can see after testing that it's only Contacts that are in my mailbox that get's resolved. That's not what we need we need the Picture of the user in Exchange or AD.
The contacts your code works with are personal contacts (the ones stored in the user's Contacts folder in their mailbox). I point this out because only attendees for which the user actually has a contact will work with this method. That being said, you should be able to use ResolveNames to resolve the email address to a contact ID.
For attendees that are part of the user's Exchange organization, you need to get photo information from AD or Exchange itself. See https://msdn.microsoft.com/EN-US/library/office/jj190905(v=exchg.150).aspx.