2014-10-07 123 views
3

我正在嘗試通過Exchange EWS獲取所有Exchange中的房間預約。Exchange EWS:如何獲取房間中的所有約會

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); 
service.UseDefaultCredentials = true;    
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 

// Return all the room lists in the organization. 
EmailAddressCollection roomLists = service.GetRoomLists(); 

System.Collections.ObjectModel.Collection<EmailAddress> rooms = service.GetRooms("[email protected]"); 

EmailAddress roomAdress = rooms[31]; 

FolderId folderid = new FolderId(WellKnownFolderName.Calendar, new Mailbox(roomAdress.Address)); 
FindItemsResults<Appointment> aps = service.FindAppointments(folderid, new CalendarView(DateTime.Now, DateTime.Now.AddHours(24))); 

如果我運行這段代碼我得到一個錯誤信息,指出:

{"The specified folder could not be found in the store."}. 

事實上,如果我告訴我這樣一個會議室郵箱的所有文件夾的集合,還有它裏面沒有文件夾。

我在做什麼錯?互聯網中的所有示例都與WellKnownFolderName.Calendar一起使用。

回答

2

該錯誤通常表明您的憑據可以連接到Exchange,但您無權訪問您嘗試訪問的日曆,因此您需要使用Add-MailboxPermission或授予訪問權限授予對郵箱的訪問權限以使用日曆文件夾添加-MailboxFolderPermissions

乾杯 格倫

+0

但是當我在Outlook中打開日曆具有相同的憑據,我沒有問題訪問它。我需要另外訪問郵箱嗎? – murratore 2014-10-08 07:52:18

+0

您是否嘗試過使用service.credentials指定憑據?您可以使用EWSEditor訪問房間郵箱http://ewseditor.codeplex.com/ – 2014-10-08 08:43:09

+1

爲日曆文件夾添加權限解決了問題。例如,要允許用戶'readonly'在'room123'上查看日曆約會: 'Add-MailboxFolderPermission -Identity [email protected]:\ Calendar -AccessRights Reviewer -User readonly @ test.example.com' – 2017-08-08 07:01:40

相關問題