murratore
murratore

Reputation: 171

Exchange EWS: How to get all appointments in a room

I am trying to get all Appointments of a Room in Exchange via 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)));

If I run this code I get an error message stating:

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

And indeed if I show me a collection of all folders for such a room mailbox, there are no folders inside it.

What am I doing wrong? All examples in the internet work with WellKnownFolderName.Calendar.

Upvotes: 3

Views: 3998

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

That error generally indicates your credentials are okay to connect to Exchange but you don't have rights to the calendar you're trying to access so you either need to grant access to the Mailbox using Add-MailboxPermission or Grant Access to the Calendar Folder using Add-MailboxFolderPermissions

Cheers Glen

Upvotes: 2

Related Questions