How to read custom field value

我们两清 提交于 2019-12-11 04:35:35

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/8626200/how-to-read-custom-field-value

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