3

我需要在用户的日历约会中搜索子字符串。我没有关于约会的任何其他信息(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);
             }
4

1 回答 1

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;
            }
         }
于 2013-08-27T12:32:40.700 回答