将子文件夹的folderId检索到Inbox

时间:2019-01-25 09:52:18

标签: c# .net outlook exchange-server exchangewebservices

我设法在Outlook中获取“收件箱”文件夹的folderID。问题是我想找到Inbox文件夹的子文件夹的folderID,并且我尝试使用此代码,但是它不起作用。好像它说Inbox文件夹有0个子文件夹,但这不是事实。有什么建议吗?

    static void Main(string[] args)
    {


        ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);


        Service.UseDefaultCredentials = false;
        Service.Credentials = new WebCredentials("xxxxx", "xxxxx");

        Mailbox ProdSupportMailbox = new Mailbox("xxxxxxxx");
        Service.TraceEnabled = true;

        Service.AutodiscoverUrl("xxxxxxx");

        FolderId folderId = FindFolderIdByDisplayName(Service, "Processed 2019", WellKnownFolderName.Inbox);

        if (folderId != null)
        {
            Console.WriteLine("The unique identifier of the folder is: " + folderId.ToString());

        }

        else
        {
            Console.WriteLine("The folder was not foundin the Inbox folder");

        }


    }

    public static FolderId FindFolderIdByDisplayName(ExchangeService service, string DisplayName, WellKnownFolderName SearchFolder)
    {

        Folder rootFolder = Folder.Bind(service, SearchFolder);

        foreach (Folder folder in rootFolder.FindFolders(new FolderView(100)))
        {

            if (folder.DisplayName == DisplayName)
            {
                return folder.Id;
            }

        }

        return null;
    }
}

}

0 个答案:

没有答案