EWS搜索子串的约会主体

时间:2013-08-23 19:44:41

标签: c# calendar exchangewebservices appointment

我需要在用户的日历约会中搜索子字符串。我没有关于约会的任何其他信息(GUID,开始日期等)。我只知道一个特定的子串在体内。

我已经阅读了几篇关于如何获得预约机构的文章,但他们通过GUID或主题进行搜索。我正在尝试使用下面的代码来搜索正文中的子字符串,但是我收到一个错误,我无法在FindItems中使用Body。

有办法做到这一点吗?假设我无法从预约中获得任何其他信息,我可以采取另一种方法吗?

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

1 个答案:

答案 0 :(得分:3)

所以事实证明你能够搜索身体,但你无法使用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;
            }
         }
相关问题