2013-11-25 2 views
2

Exchange 웹 서비스의 모든 연락처 (단지 처음 몇 백)받는 방법 :내가이 같은 접촉을 반복하는 Exchange 웹 서비스를 사용하고

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; 
} 
관련 문제