We help IT Professionals succeed at work.

Exchange Folder.FindItems until end of messages.

whorsfall
whorsfall asked
on
Hi,

I am using the Microsoft.Exchange.WebServices Nuget package the process mail messages.

Here is an extract of my code:


DateTime start_date = new DateTime(2018, 7, 1); //Year, month, day
DateTime end_date = new DateTime(2019, 6, 30);
               
SearchFilter greaterthanfilter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, start_date);
SearchFilter lessthanfilter = new SearchFilter.IsLessThanOrEqualTo(ItemSchema.DateTimeReceived, end_date);
SearchFilter filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, greaterthanfilter, lessthanfilter);

Folder folder = Folder.Bind(_service, WellKnownFolderName.Inbox); //Or the folder you want to search in
FindItemsResults<Item> results = folder.FindItems(filter, new ItemView(100));

Now this gets the first group.

How to i next get the next group until it ends.

In other words:

get messages

while (more_messages)
{
  get next set of messages
}

Thanks,

Ward.
Comment
Watch Question

"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:

You need to provide an offset

  ItemView(100, Offset)

and increment that offset by the page size each time.