1

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 + "  ");
    }
}
ca9163d9
  • 27,283
  • 64
  • 210
  • 413

1 Answers1

1

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

Community
  • 1
  • 1
Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • I tried to use the code in the link but it cannot find the folder - the folder shows "xxxx yyyy" in my Outlook and I don't know if it has any parent folder so I tried to enumerate all folders to get the full path. I tried to modify `int.MaxValue` to 1000. – ca9163d9 Nov 25 '14 at 06:23
  • 1
    A few questions is this a Shared folder in your Mailbox? or is it a Public Folder the code you posted shows a public folder search ?. Do you understand what public folders in Exchange are ? If you look at the Folder List in your Mailbox under which hierarchy is it ? http://office.microsoft.com/en-au/outlook-help/show-all-folders-HP005242678.aspx .I would suggest you use the EWSeditor https://ewseditor.codeplex.com/ and work out where the folder is first. – Glen Scales Nov 26 '14 at 05:47