我们如何在约会中显示所需与会者和可选与会者的照片?根据文档,应该可以使用此方法(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);
}
}
但是,在加载约会对象时,必需与会者和可选与会者数组仅返回电子邮件地址对象。如何将 EmailAdress 转换为 ItemId,以便可以使用文档中的 GetContactsPhoto 方法?
//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);
}
customPropertySet 如下所示:
//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);
尝试将电子邮件地址作为 Id 传递,但返回一条错误消息,指出"id 格式不正确"。
更新1:尝试使用Jason Johnson在答案中指出的Resolve方法。他正确地指出,我可以在测试后看到只有我邮箱中的联系人才能解决。这不是我们需要的,我们需要Exchange或AD中用户的图片。
代码使用的联系人是个人联系人(存储在用户邮箱的"联系人"文件夹中的联系人)。我指出这一点是因为只有用户实际有联系人的与会者才会使用此方法。话虽如此,您应该能够使用 ResolveNames 将电子邮件地址解析为联系人 ID。
对于属于用户 Exchange 组织的与会者,您需要从 AD 或 Exchange 本身获取照片信息。请参阅 https://msdn.microsoft.com/EN-US/library/office/jj190905(v=exchg.150).aspx。
如果您使用的是 Exchange 2013 或 Office 365,则可以使用 FindPeople API 通过收件人的电子邮件地址获取联系人。