views:

108

answers:

1

Is there a way to search Exchange using the EWS Managed API for all email messages across ALL folders. I'm using the FindItems API call -- but that appears to require that the search be confined to a single folder.

   private void InternalPurgeProcessFolder(FolderId folderId, ExchangeService service, SearchFilter searchCriteria) {

        Logger.Info("Processing folder {0}", folderId.FolderName);

        int pageSize = _runtimeParameters.ExchangeRetrievalPageSize;
        ItemView itemView = new ItemView(pageSize);
        itemView.PropertySet = Utils.BasicPropertySet();
        const int maxInterationsForTesting = 2;
        int iterations = 0;
        FindItemsResults<Item> findResults;
        do {
            ++iterations;
            Logger.Debug("Start of iteration {0}", iterations);
            findResults = service.FindItems(folderId, searchCriteria, itemView);
            _dumper.ListDatesAndSubjectsBrief(findResults);
            itemView.Offset += pageSize;
        } while ((findResults.MoreAvailable) && (iterations < maxInterationsForTesting));
    }
+1  A: 

To find items across folders you can create a search folder and in the SearchFolderParameters set the RootFolderIds to the root folder of the mailbox and the traversal mode to SearchFolderTraversal.Deep.

Laurion Burchall