如何在Exchange Web服务中获取所有联系人(不仅仅是前几百个) [英] How to get all contacts in Exchange Web Service (not just the first few hundreds)

查看:127
本文介绍了如何在Exchange Web服务中获取所有联系人(不仅仅是前几百个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Exchange Web Service迭代这样的联系人:

I'm using Exchange Web Service to iterate through the contacts like this:

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?甚至更多?

Now this restricts the result set to the first 500 contacts - how do I get the next 500? Is there some kind of paging possible? Of course I could set 1000 as Limit. But what if there are 10000? Or 100000? Or even more?

推荐答案

您可以使用在此处解释

FindItemsResults contains更多信息可能会告诉您完成的时间。

FindItemsResults contains a MoreAvailable probably that will tell you when you're done.

基本代码如下:

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;
}   

这篇关于如何在Exchange Web服务中获取所有联系人(不仅仅是前几百个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆