2013-11-25 68 views
2

我使用Exchange Web服务,通​​过这样的接触迭代在Exchange Web服务的所有联系人(不只是第一几百):如何获得

ItemView view = new ItemView(500); 
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ContactSchema.DisplayName); 
FindItemsResults<Item> findResults = _service.FindItems(WellKnownFolderName.Contacts, view); 
foreach (Contact item in findResults.Items) 
{ 
    [...] 
} 

现在,这将结果集限制到前500名联系人 - 我如何获得下一个500名?有没有可能的分页?当然我可以设置1000作为限制。但万一有10000?还是100000?还是更多?

回答

3

你可以做'分页搜索'为explained here

FindItemsResults包含一个MoreAvailable可能会告诉你什么时候完成。

基本的代码如下所示:

while (MoreItems) 
{ 
// Write out the page number. 
Console.WriteLine("Page: " + offset/pageSize); 

// Set the ItemView with the page size, offset, and result set ordering instructions. 
ItemView view = new ItemView(pageSize, offset, OffsetBasePoint.Beginning); 
view.OrderBy.Add(ContactSchema.DisplayName, SortDirection.Ascending); 

// Send the search request and get the search results. 
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Contacts, view); 

// Process each item. 
foreach (Item myItem in findResults.Items) 
{ 
    if (myItem is Contact) 
    { 
     Console.WriteLine("Contact name: " + (myItem as Contact).DisplayName); 
    } 
    else 
    { 
     Console.WriteLine("Non-contact item found."); 
    } 
} 

// Set the flag to discontinue paging. 
if (!findResults.MoreAvailable) 
    MoreItems = false; 

// Update the offset if there are more items to page. 
if (MoreItems) 
    offset += pageSize; 
}