Reputation: 58
I have one exchange account with the access to all of our room email-accounts.
I need to get all planned appointments for each room using this "admin-account".
At the beginning I got the login set for each account.
I stored the necessary information in objects and then I used the following code to get all the wanted data.
string roomName = rooms[i].RoomName;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Timeout = 5000;
service.Credentials = new NetworkCredential(rooms[i].AccountName + "@company.com", rooms[i].AccountPassword);
service.AutodiscoverUrl(rooms[i].AccountName + "@company.com");
DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(7);
const int NUM_APPTS = 280;
Console.WriteLine("Start binding calendar objects");
//init calender folder object
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
Console.WriteLine("Start setting start and end time and number of appointments to retrieve");
//set start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
Console.WriteLine("limit the properties");
//limit the properties returned to subject(name of the person who booked the room, name of the room, start and end time(datetime) of the meeting
cView.PropertySet = new PropertySet(AppointmentSchema.Organizer, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Subject);
//retrieve Collection of appointments by using the calendar view
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
Using this code with the admin-account just returns nothing.
I tried to get all rooms for this account with the following code
System.Collections.ObjectModel.Collection<EmailAddress> myRoomAddresses = service.GetRooms("[email protected]");
But this returns only a ServiceResponseException: nothing found.
Does anybody know a way to get all rooms + appointments, only using the admin-account ?
Upvotes: 0
Views: 347
Reputation: 22032
You should use FolderId overload to specify the Mailbox you want to access else you code will just always access the Calendar Folder of the credentials your using eg replace the line
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
with
FolderId CalendarFolderIdVal = new FolderId(WellKnownFolderName.Calendar,rooms[i].AccountName + "@company.com");
CalendarFolder calendar = CalendarFolder.Bind(service, CalendarFolderIdVal, new PropertySet());
You should just do the Autodiscover once using the Email Address of the Service account.
System.Collections.ObjectModel.Collection<EmailAddress> myRoomAddresses = service.GetRooms("[email protected]");
If this room list exists and has be populated it will just return the EmailAddress's of the Room in that list. That error indicates the List doesn't exist.
Cheers Glen
Upvotes: 1