How to set the contact title using Exchange Web Services Managed API

自古美人都是妖i 提交于 2019-12-01 21:04:27

问题


I'm trying to create a new contact using the EWS API. I can set all the values i needed except the contact title property. I tried the code:

oContact = new Contact(oService);
oContact.GivenName = "John";
oContact.Surname = "Doe";
oContact.Displayname = oContact.Surname;

// set the title property as extended property
// reference: http://msdn.microsoft.com/en-us/library/gg274394.aspx
ExtendedPropertyDefinition oTitleProp = new ExtendedPropertyDefinition(
  new Guid("{00062004-0000-0000-C000-000000000046}"),
  0x3A45,
  MapiPropertyType.String);
oContact.SetExtendedProperty(oTitleProp, "Mr.");

oContact.Save();

I'm not getting an error but when i check the title field in outlook 2010, it's empty. I’m using Exchange 2010.

Any ideas what i did wrong?

Kind regards

Volkmar


回答1:


Short Answer

When creating the extended property definition, instead of the code you have above, don't use the constructor where you specify the propertySetId. Instead, construct it like this:

ExtendedPropertyDefinition oTitleProp = new ExtendedPropertyDefinition(
    0x3A45,
    MapiPropertyType.String);

Longer Answer

That reference you have from Microsoft is interesting. From reading the chapter about extended prorperties in Inside Microsoft Exchange Server 2007 Web Services, I always thought that for extended properties not in the custom range (those below 0x8000), you'd leave out the propertySetId when referencing them, so it's interesting that on that page, Microsoft seems to imply you'd use it.

For what it's worth, there's a freely available appendix (Appendix C) to Inside Microsoft Exchange Server 2007 Web Services that also documents extended properties at http://www.microsoft.com/mspress/companion/9780735623927/ that might be clearer than that Microsoft page on when to use propertySetId and when not to.

There's also a more-accurate list of properties and their corresponding property sets at http://msdn.microsoft.com/en-us/library/cc433490(EXCHG.80).aspx



来源:https://stackoverflow.com/questions/4863364/how-to-set-the-contact-title-using-exchange-web-services-managed-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!