I am looping through every email in a folder which contains about 26,000 emails. When my program hits email 6,000 (based off of a counter) it ends. Why does it not loop through every email?
int offset = 0;
int pageSize = 1000;
bool more = true;
ItemView view = new ItemView(pageSize, offset,OffsetBasePoint.Beginning);
view.PropertySet = PropertySet.FirstClassProperties;
FindItemsResults<Item> findResults = exchsvc1.FindItems(folder, view);
while (more)
{
foreach (Item mail in findResults.Items)
{
do stuff
}
offset = pageSize;
pageSize = pageSize + pageSize;
view = new ItemView(pageSize, offset, OffsetBasePoint.Beginning);
findResults = exchsvc1.FindItems(folder, view);
more = findResults.MoreAvailable;
}
Looking at your code I would say
offset = pageSize;
pageSize = pageSize + pageSize;
Is your problem, you should just be incrementing the offset by the number of Items that is returned. If you look at your code your increasing the page size by 1000 with every iteration. throttling means you won't get more the 1000 items back in one page so the offset line is essentially skipping items because of this logic. Just use
offset += findResults.Items.Count
instead the pageSize should not change and should not be anymore than 1000 and you offset should always be based on the number items returned.