Microsoft.Exchange.WebServices.Data.ServiceResponseException: 在商店中找不到指定的文件夹

Microsoft.Exchange.WebServices.Data.ServiceResponseException : The specified folder could not be found in the store

在 office365 中,我正在尝试使用 EWS 访问另一个用户的对话历史记录文件夹 api.The 正在尝试访问的用户具有邮箱的完全访问权限。如果我使用 owa 连接到邮箱,我可以访问对话历史文件夹,包括所有其他文件夹。但是当我尝试使用 ews api 从代码进行连接时,抛出以下异常:

Microsoft.Exchange.WebServices.Data.ServiceResponseException occurred HResult=-2146233088 Message=The specified folder could not be found in the store. Source=Microsoft.Exchange.WebServices StackTrace:

这里是相关代码

        var mailbox = new Mailbox(lyncUser.UserName);
        var lyncFolderId = new FolderId(WellKnownFolderName.ConversationHistory, mailbox);
        var lyncFolder = Folder.Bind(_exchangeService, lyncFolderId);

此外,如果连接到 WellKnownFolderName.Inbox,则不会发生异常。

Answer From Glen Scales : The WellKnowFolderEnum only works if the folder was created via the Lync 2013 client if the Mailbox is old and has been using older lync clients then you need to search for the folder via name eg see https://msdn.microsoft.com/en-us/library/office/hh243707%28v=office.14%29.aspx。通常您希望同时使用这两种方法,例如尝试先绑定到 WellKnowFolderEnum,如果失败则使用搜索方法。