gpt4 book ai didi

c# - 如何使用 EWS 托管 API 从文件夹和公共(public)文件夹的子文件夹中获取所有项目

转载 作者:可可西里 更新时间:2023-11-01 07:59:59 28 4
gpt4 key购买 nike

如何在 exchange server2010 uisng 托管 API 中检索“公用文件夹”及其“子文件夹”中的所有项目???

rootfolder = Folder.Bind(service,WellKnownFolderName.PublicFoldersRoot);
rootfolder.Load();
foreach (Folder folder in rootfolder.FindFolders(new FolderView(int.MaxValue)))
{
FindItemsResults<Item> findResults = folder.FindItems(iv);
foreach (Item item in findResults)

{
//get item info;
}
}

“如果我这样做,我不会在它的子文件夹中获取项目。公共(public)文件夹也不支持深度遍历查询。我如何从公共(public)文件夹的子文件夹中获取项目???”

最佳答案

要获取所有文件夹,请使用以下代码:

public void GetAllFolders(ExchangeService service, List<Folder> completeListOfFolderIds)
{
FolderView folderView = new FolderView(int.MaxValue);
FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, folderView);
foreach (Folder folder in findFolderResults)
{
completeListOfFolderIds.Add(folder);
FindAllSubFolders(service, folder.Id, completeListOfFolderIds);
}
}

private void FindAllSubFolders(ExchangeService service, FolderId parentFolderId, List<Folder> completeListOfFolderIds)
{
//search for sub folders
FolderView folderView = new FolderView(int.MaxValue);
FindFoldersResults foundFolders = service.FindFolders(parentFolderId, folderView);

// Add the list to the growing complete list
completeListOfFolderIds.AddRange(foundFolders);

// Now recurse
foreach (Folder folder in foundFolders)
{
FindAllSubFolders(service, folder.Id, completeListOfFolderIds);
}
}

获取所有项目:

List<Folder> completeListOfFolderIds = new List<Folder>();
//Fills list with all public folders and subfolders
GetAllFolders(service, completeListOfFolderIds);
foreach(Folder folder in completeListOfFolderIds)
{
ItemView itemView = new ItemView(int.MaxValue);
FindItemsResults<Item> searchResults = service.FindItems(folder.Id, itemView);
//do something with item list
}

FYI FindFolders/FindItems 仅返回前 1000 个项目,因此如果您有大量结构,则必须更改此代码以克服此问题。

关于c# - 如何使用 EWS 托管 API 从文件夹和公共(public)文件夹的子文件夹中获取所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13877629/

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