ca9163d9
ca9163d9

Reputation: 29209

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

Upvotes: 1

Views: 2127

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

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

Upvotes: 1

Related Questions