gpt4 book ai didi

c# - Microsoft Exchange Folders.findItems 结果限制为 1000

转载 作者:太空狗 更新时间:2023-10-30 01:23:04 27 4
gpt4 key购买 nike

我正在尝试从 Microsoft Exchange 的联系人文件夹中获取联系人列表。
即使文件夹中有更多项目,结果也只返回 1000 项。
这是我的代码。

FindFoldersResults r = service.FindFolders(new FolderId(WellKnownFolderName.PublicFoldersRoot), new FolderView(10));
Folder folder = getFolder("test", r.Folders);
ContactsFolder contactsfolder = ContactsFolder.Bind(service, new FolderId(folder.Id.ToString()), new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount));
FindItemsResults<Item> items = folder.FindItems(new ItemView(contactsfolder.TotalCount));

我怎样才能让它返回所有项目?

最佳答案

正如 Jason 引用的文章所建议的那样,分页是关键。这是我针对 Office365 Exchange 服务器使用的代码,用于获取给定文件夹中所有电子邮件的列表(超过 20,000 封电子邮件,在页面大小为 100 时工作速度非常快):

            // via https://msdn.microsoft.com/en-us/library/office/dn592093(v=exchg.150).aspx
int pageSize = 100;
int offset = 0;
ItemView view = new ItemView(pageSize + 1, offset);
view.PropertySet = new PropertySet(ItemSchema.Subject, ItemSchema.DateTimeSent);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
view.Traversal = ItemTraversal.Shallow;

bool moreItems = true;
ItemId anchorId = null;

while (moreItems)
{
FindItemsResults<Item> results = service.FindItems(buildsFolderId, view);
moreItems = results.MoreAvailable;
if (moreItems && anchorId != null)
{
// Check the first result to make sure it matches
// the last result (anchor) from the previous page.
// If it doesn't, that means that something was added
// or deleted since you started the search.
if (results.Items.First<Item>().Id != anchorId)
{
Console.Error.WriteLine("The collection has changed while paging. Some results may be missed.");
}
}

if (moreItems)
{
view.Offset += pageSize;
}

anchorId = results.Items.Last<Item>().Id;

// Because you’re including an additional item on the end of your results
// as an anchor, you don't want to display it.
// Set the number to loop as the smaller value between
// the number of items in the collection and the page size.
int displayCount = results.Items.Count > pageSize ? pageSize : results.Items.Count;

for (int i = 0; i < displayCount; i++)
{
Item item = results.Items[i];

Console.WriteLine("[" + item.DateTimeSent + "] " + item.Subject);
}

Console.Error.WriteLine("Current offset: {0}/{1}", view.Offset, folder.TotalCount);
}

关于c# - Microsoft Exchange Folders.findItems 结果限制为 1000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12200109/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com