3

我目前正在尝试通过 Microsoft 的 EWS 托管 API 从 Outlook 联系人对象中读取某些属性。我从FindItems()函数中检索这些联系人对象。其中一些字段是扩展属性,例如TitleorUser1字段,我很难阅读它们。目前,我有:

Guid propertySetId = new Guid("{00062004-0000-0000-C000-000000000046}");
ExtendedPropertyDefinition titleProp = new ExtendedPropertyDefinition(propertySetId, 0x3A45, MapiPropertyType.String);
ExtendedPropertyDefinition user1Prop = new ExtendedPropertyDefinition(propertySetId, 0x804F, MapiPropertyType.String);

string title, user1;
contact.TryGetProperty(titleProp, out title);
contact.TryGetProperty(user1Prop, out user1);

运行它时,TryGetProperty总是返回 false。我已验证这些字段已在 Outlook 中为我正在搜索的联系人填充。

编辑:这就是我检索联系人对象的方式。

ExchangeService service = //...
Mailbox userMailbox = new Mailbox(emailAddress);
FolderId folderId = new FolderId(WellKnownFolderName.Contacts, userMailbox);
FindItemsResults<Item> results;
const string AQS = "Category:~>\"CategoryTag\"";
ItemView view = new ItemView(200);
results = service.FindItems(folderId, AQS, view);
foreach (var result in results)
{
    Contact contact = result as Contact;
    //...Try to read fields
}
4

1 回答 1

5

您需要更改ItemView以包含您希望访问的属性( )。PropertySet

var user1Val = string.Empty;
var user1Prop = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 0x804F, MapiPropertyType.String);
ExtendedPropertyDefinition[] extendedFields = new ExtendedPropertyDefinition[] { user1Prop };
PropertySet extendedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, extendedFields);
ItemView view = new ItemView(200) { PropertySet = extendedPropertySet };
// ...
var title = contact.CompleteName.Title; // Title value
contact.TryGetProperty(user1Prop, out user1Val); // user field 1 value
于 2012-04-30T16:06:53.200 回答