我们如何在约会中显示要求和可选参加者的照片?根据文档,应该可以使用这种方法(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);
}
}
但是在加载约会对象时,RequiredAttendees 和 OptionalAttendees 数组只返回 EmailAdress 对象。如何将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 中的用户图片。