如何从“公共文件夹”和“子文件夹”的所有项目,以换取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;
}
}
“如果我不喜欢这个我没有得到项目目前在it..public文件夹的子文件夹不支持深度遍历查询too..How我可以得到公共文件夹的子文件夹的项目???”
要获得所有文件夹,使用下面的代码:
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
}
您需要执行公用文件夹树的递归遍历。 你不能在公共文件夹进行深度遍历。
public IEnumerable<Item> FindItemsInSubfolders(FolderId root, SearchFilter itemsFilter)
{
foreach (Folder folder in service.FindFolders(root, new FolderView(int.MaxValue) { Traversal = FolderTraversal.Deep }))
foreach(Item item in service.FindItems(folder.Id, itemsFilter, new ItemView(int.MaxValue)))
yield return item;
foreach (Item item in service.FindItems(root, itemsFilter, new ItemView(int.MaxValue)))
yield return item;
}
文章来源: How To Get all ITEMS from Folders and Sub-folders of PublicFolders Using EWS Managed API