Search code examples
c#outlookexchangewebservicesexchange-server-2007

Access Outlook user properties from EWS


I'm trying to create an application that use the EWS api to access contacts.

I need to look at one of the outlook user properties in this process but I cant see how to get it at using EWS. At the moment ive just tried...

service.Url = new Uri("https://url/ews/Exchange.asmx");
service.Credentials = new WebCredentials("credentials");
var results = service.FindItems(folderId, new ItemView(100));
foreach (var item in results)
{
     Contact contact = item as Contact;
     foreach (var prop in contact.ExtendedProperties)
     {
            Console.WriteLine(prop.Value.ToString());
     }
}

Which compiles and executes without a problem, but for every contact the ExtendedProperties count is 0 which in outlook its about 30.

So how can I get the properties I'm looking for?

Just an FYI. Im using exhcnage 2007.

Thanks.


Solution

  • 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)});