如果我有日历约会,如何获取联系人的 itemID?
How do I get the itemID for a contact given I have an calendar appointment?
我们如何在约会中显示必选和可选参加者的照片?根据文档,应该可以使用此方法检索照片 (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 数组仅 returns 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 传递,但 returns 一条错误消息指出 "id is malformed".
更新 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 通过收件人的电子邮件地址获取联系人。
我们如何在约会中显示必选和可选参加者的照片?根据文档,应该可以使用此方法检索照片 (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 数组仅 returns 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 传递,但 returns 一条错误消息指出 "id is malformed".
更新 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 通过收件人的电子邮件地址获取联系人。