Exchange Web Service FolderId for a not well known folder name

后端 未结 3 1072
春和景丽
春和景丽 2020-12-16 11:00

I have a folder in an Exchange mailbox that is a child of the root (not Inbox).

How do I get the ID of such folder using EWS Managed API?

Only examples I

3条回答
  •  温柔的废话
    2020-12-16 11:51

    A bit late, but the following is what I used to find my folder:

    var view = new FolderView(1);
    view.Traversal = FolderTraversal.Deep;
    var filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Rejected");
    var results = Service.FindFolders(WellKnownFolderName.Root, filter, view);
    if (results.TotalCount < 1)
        throw new Exception("Cannot find Rejected folder");
    if (results.TotalCount > 1)
        throw new Exception("Multiple Rejected folders");
    Rejected = Folder.Bind(Service, results.Folders.Single().Id);
    

    Edit: Apparently my code did not work on nested heirarchies. I added a line as per cookiemonster's suggested edit.

提交回复
热议问题