简体   繁体   中英

Cannot find public folder using Exchange web service API 2.0?

My outlook client has a shared folder "xxxx yyyy". However, the following code, which iterates all the folder and sub folder recursively, doesn't print out the folder. Why the code cannot get the folder?

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 + "  ");
    }
}

If your using Exchange 2010 or later don't use

var folderView = new FolderView(int.MaxValue);

Throttling will limit the results returned to 1000 so if you expect more the 1000 entries to be return then you'll need to page the results. However it doesn't make much sense to enumerate through every public folder to get the target look at the method in the following link

Searching Of Folders in Public Folders by giving its PATH Name

if the folder is in your mailbox then just do a search for that based on the name eg

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

Cheers Glen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM