如何使用EWS从Outlook联系人中读取扩展属性 [英] How to read extended properties from Outlook contacts using EWS

查看:123
本文介绍了如何使用EWS从Outlook联系人中读取扩展属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently attempting to read certain properties from Outlook Contact objects through Microsoft's EWS managed API. I retrieve these Contact objects from the FindItems() function. Some of these fields are extended properties such as the Title or User1 field and I'm having difficulty reading them. At the moment, I have:

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中填充我要搜索的联系人.

When running this, TryGetProperty always returns false. I have verified that these fields are populated in Outlook for the contacts that I am searching for.

这是我检索联系人对象的方式.

This is how I retrieve the contact objects.

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
}

推荐答案

您需要更改包括属性(

You need to change the ItemView to include the properties (PropertySet) you wish to access.

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

这篇关于如何使用EWS从Outlook联系人中读取扩展属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆