Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 742
murratore Avatar asked Jan 26 '26 18:01

murratore


1 Answers

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

like image 57
Glen Scales Avatar answered Jan 29 '26 13:01

Glen Scales