none
[EWS]: FindItems does not find emails by HTML body in SearchFolder. RRS feed

  • Question

  • Hello, 

    I'm using SearchFolder to do a deep traversal search on an EWS connected to Office365. The problem is that I don't get all the matching email results when using FindItems for this folder. I don't get emails with HTML body that contains "text" (for Text body it work). But when I using FindItems for a normal folder it return all emails.

    var subjectFilter = new SearchFilter.ContainsSubstring(ItemSchema.Subject, text, ContainmentMode.Substring, ComparisonMode.IgnoreCase);
    var bodyFilter = new SearchFilter.ContainsSubstring(ItemSchema.Body, text, ContainmentMode.Substring, ComparisonMode.IgnoreCase);
    var searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, subjectFilter, bodyFilter);
    var findItems = service.FindItems(searchFolderID, searchFilter, view);


    • Edited by vangog63 Tuesday, April 5, 2016 8:50 AM
    Friday, April 1, 2016 12:13 PM

All replies

  • What is the Search Folder doing then (eg what search terms) ? Its generally not a good idea to put a restriction on top of another restriction(eg the search folder). Given what your doing and your example a better idea maybe just use eDiscovery you can then search both the Mailbox and Archive https://msdn.microsoft.com/en-us/library/office/jj190897(v=exchg.150).aspx because this is using the Content indexing it should also give better performance.

    Cheers
    Glen

    Monday, April 4, 2016 2:53 AM
  • I need to implement a search for messages in all folders with support versions of Exchange starting with 2010 SP1.

    eDiscovery is supported starting with 2013.

    To solve this task, I created a SearchFolder.

    var searchFolder = new SearchFolder(service);
    searchFolder.DisplayName = "All items";
    searchFolder.SearchParameters.RootFolderIds.Add(WellKnownFolderName.MsgFolderRoot);
    searchFolder.SearchParameters.Traversal = SearchFolderTraversal.Deep;
    searchFolder.SearchParameters.SearchFilter = new SearchFilter.Exists(ItemSchema.ItemClass);
    searchFolder.Save(WellKnownFolderName.Root);
    I haven't found a better solution yet.
    Tuesday, April 5, 2016 8:25 AM
  • Are you building a Application for end users to use or Admins ? if its for administrators then using the Exchange Management Shell and the Search-Mailbox cmdlet is probably a better option.

    Given the type of search your trying to do (eg a Substring on the Body and Subject of every message) using a SearchFolder and SearchFilter probably isn't the best approach your not going yield fast results on large Mailboxes. My suggestion would be you use eDiscovery on 2013 and above and for 2010 you look at doing per folder search and using AQS which will take advantage of Content indexes. Anyway you do this for large mailboxes its going to take time to yield results with the Folder approach you can peform the search asynchronously eg if as you know most of the results are going to be in the Inbox your search that first return the first results set back to user and do more searches while the user is dealing with the first set which is more or less the way Outlook is doing it.

    Cheers
    Glen

    Wednesday, April 6, 2016 3:57 AM
  • Thank you, Glen.

    I thought about this decision. Hovewer, with such an approach, the Exchange can block my requests when EWS throttling policies will be exceeded. Large Mailboxes can contain more than 100 folders. And if I'm not mistaken, Outlook uses a different protocol.

    Wednesday, April 6, 2016 9:40 AM