我的Outlook客户端有一个共享文件夹“xxxx yyyy”。但是,以下代码以递归方式迭代所有文件夹和子文件夹,不会打印出该文件夹。为什么代码无法获取文件夹?
private static void PrintAllPubFolder(ExchangeService service)
{
var folderView = new FolderView(int.MaxValue);
var findFolderResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, folderView);
foreach (var folder in findFolderResults.Where(x => !ignore.Any(i => i == x.DisplayName)))
{
Console.WriteLine(folder.DisplayName);
PrintSubFolder(service, folder.Id, " ");
}
}
private static void PrintSubFolder(ExchangeService service, FolderId folderId, string p)
{
var folderView = new FolderView(int.MaxValue);
var findFolderResults = service.FindFolders(folderId, folderView);
foreach (var folder in findFolderResults.Where(x => !ignore.Any(i => i == x.DisplayName)))
{
Console.WriteLine("{0}{1}", p, folder.DisplayName);
PrintSubFolder(service, folder.Id, p + " ");
}
}
答案 0 :(得分:1)
如果您使用的是Exchange 2010或更高版本,请不要使用
var folderView = new FolderView(int.MaxValue);
限制会将返回的结果限制为1000,因此如果您希望返回1000个条目,那么您需要分页结果。但是,枚举每个公共文件夹以使目标查看以下链接中的方法没有多大意义
Searching Of Folders in Public Folders by giving its PATH Name
如果文件夹在您的邮箱中,那么只需根据名称进行搜索,例如
FolderView ffView = new FolderView(1000);
ffView.Traversal = FolderTraversal.Deep;
SearchFilter fSearch = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "xxxx yyyy");
FindFoldersResults ffResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot, fSearch, ffView);
干杯 格伦