Search code examples
c#exchangewebservicesexchange-server-2007

How to read custom field value


I am using the below code to read the mails from my inbox using ews. I am able to read Subject etc. But how to read custom field value?

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential("username", "password", "domain"); 
service.Url = new Uri("https://server/ews/exchange.asmx"); 
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100));

foreach (Item item in findResults.Items)
{
    string str=item.Subject;
    foreach (ExtendedProperty extendedProperty in item.ExtendedProperties)
    { }
}

I tried item.ExtendedProperties. But the count is always zero. Can any one tell me how to read the custom field value?

Thanks in advance


Solution

  • According to this MSDN article, you need to add a property set for the extended properties that you want to retrieve to the ItemView parameter of the FindItems method.

    For example, your line:

    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100));
    

    becomes:

    ItemView view = new ItemView(100);
    
    Guid MyPropertySetId = new Guid("{C11FF724-AA03-4555-9952-8FA248A11C3E}");
    
    view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, extendedPropertyDefinition);
    
    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, view);