如何读取自定义字段值
本文关键字:自定义 字段 读取 何读取 | 更新日期: 2023-09-27 18:18:49
我使用下面的代码从我的收件箱中使用ews读取邮件。我能够阅读学科等。但是如何读取自定义字段值呢?
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)
{ }
}
我尝试了item.ExtendedProperties。但计数总是零。有人能告诉我如何读取自定义字段值吗?
Thanks in advance
根据这篇MSDN文章,您需要为您想要检索的扩展属性添加一个属性集到FindItems方法的ItemView参数中。
例如:
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100));
就变成:
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);