c#-EWS搜索约会正文的子字符串
作者:互联网
我需要在用户的日历约会中搜索子字符串.我没有有关约会的其他任何信息(GUID,开始日期等).我只知道正文中有特定的子字符串.
我已经阅读了几篇有关如何获取约会的正文的文章,但是它们是按GUID或主题进行搜索的.我正在尝试使用下面的代码在正文中搜索子字符串,但是出现一个错误,提示我无法在FindItems中使用正文.
有没有办法做到这一点?假设我没有办法从约会中获取任何其他信息,是否可以采取其他方法?
//Variables
ItemView view = new ItemView(10);
view.PropertySet = new PropertySet(EmailMessageSchema.Body);
SearchFilter sfSearchFilter;
FindItemsResults<Item> findResults;
foreach (string s in substrings)
{
//Search for messages with body containing our permURL
sfSearchFilter = new SearchFilter.ContainsSubstring(EmailMessageSchema.Body, s);
findResults = service.FindItems(WellKnownFolderName.Calendar, sfSearchFilter, view);
if (findResults.TotalCount != 0)
{
Item appointment = findResults.FirstOrDefault();
appointment.SetExtendedProperty(extendedPropertyDefinition, s);
}
解决方法:
因此,事实证明您可以搜索正文,但无法使用FindItems返回正文.如果要使用它,则必须稍后加载.因此,不是将我的属性设置为主体,而是将其设置为IdOnly,然后将SearchFilter设置为遍历ItemSchema的主体.
//Return one result--there should only be one in this case
ItemView view = new ItemView(1);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
//variables
SearchFilter sfSearchFilter;
FindItemsResults<Item> findResults;
//for each string in list
foreach (string s in permURLs)
{
//Search ItemSchema.Body for the string
sfSearchFilter = new SearchFilter.ContainsSubstring(ItemSchema.Body, s);
findResults = service.FindItems(WellKnownFolderName.Calendar, sfSearchFilter, view);
if (findResults.TotalCount != 0)
{
Item appointment = findResults.FirstOrDefault();
appointment.SetExtendedProperty(extendedPropertyDefinition, s);
...
appointment.Load(new PropertySet(ItemSchema.Body));
string strBody = appointment.Body.Text;
}
}
标签:calendar,exchangewebservices,appointment,c 来源: https://codeday.me/bug/20191122/2063096.html