-->

How to set the contact title using Exchange Web Se

2019-02-23 23:51发布

问题:

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