我有一个交换帐户,可以访问我们所有的房间电子邮件帐户 我需要使用这个" admin-account"。
获得每个房间的所有计划预约一开始我获得了每个帐户的登录设置 我将必要的信息存储在对象中,然后使用以下代码获取所有想要的数据。
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);
将此代码与admin-account一起使用只会返回任何内容。
我尝试使用以下代码获取此帐户的所有房间
System.Collections.ObjectModel.Collection<EmailAddress> myRoomAddresses = service.GetRooms("roomsync@company.com");
但是这只返回一个ServiceResponseException:找不到任何内容。
是否有人知道如何获得所有房间+约会,只使用管理员帐户?
答案 0 :(得分:1)
您应该使用FolderId重载来指定您要访问的邮箱,否则您的代码将始终访问您使用的凭据的日历文件夹,例如替换行
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
带
FolderId CalendarFolderIdVal = new FolderId(WellKnownFolderName.Calendar,rooms[i].AccountName + "@company.com");
CalendarFolder calendar = CalendarFolder.Bind(service, CalendarFolderIdVal, new PropertySet());
您应该只使用服务帐户的电子邮件地址进行自动发现。
System.Collections.ObjectModel.Collection<EmailAddress> myRoomAddresses = service.GetRooms("roomsync@company.com");
如果此房间列表存在且已填充,则只返回该列表中房间的EmailAddress。该错误表明列表不存在。
干杯 格伦