Access Outlook user properties from EWS

最后都变了- 提交于 2019-12-01 09:43:17

You need to define the properties you want to get - EWS does not permit you to enumerate user properties.

The Userproperties are in the namespace PublicStrings.

private static readonly ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "MyCustomProperty", MapiPropertyType.String);

You can then use the definition in a FindItems request:

var items = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100) { PropertySet =   new PropertySet(BasePropertySet.FirstClassProperties, CustomProperty)});

I had the same problem, solved.

var customProp1 = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                        "myCustomPropOne", MapiPropertyType.String);

var customProp2 = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,
                      "myCustomPropTwo", MapiPropertyType.String);

var userFields = new ExtendedPropertyDefinition[] { customProp1, customProp2 };

var extendedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, userFields);

var contactItems = service.FindItems(WellKnownFolderName.Contacts, new ItemView(100)
            { PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, extendedPropertySet) });
// Looping contacts
    foreach (Item item in contactItems){
        object firstProp;              
        if (item.TryGetProperty(customProp1, out firstProp) && firstProp != null)
        {
               var val = firstProp.ToString();
        }
        object secondProp;
        if (item.TryGetProperty(customProp2, out secondProp) && secondProp != null)
        {
               var val = secondProp.ToString();
        }
     } // loop ends

myCustomPropOne & myCustomPropTwo are names of user defined properties you set in outlook/editor. ref

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