2015-12-07 77 views
0

我有一個交換賬戶,可以訪問我們所有房間的電子郵件賬戶。
我需要使用此「管理帳戶」獲取每個房間的所有計劃約會。通過一個賬戶從不同房間獲取預約

開始時我爲每個帳戶設置了登錄名。
我將所需的信息存儲在對象中,然後使用以下代碼獲取所有需要的數據。

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); 

對管理員帳戶使用此代碼只會返回任何內容。

我試圖讓所有房間此帳戶用下面的代碼

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

但這僅返回ServiceResponseException:沒有發現。

有沒有人知道一種方式來獲得所有房間+約會,只使用管理帳戶?

回答

1

您應該使用FolderId超載指定要訪問否則你的代碼將只是隨時存取例如使用憑證的日曆文件夾的郵箱與

FolderId CalendarFolderIdVal = new FolderId(WellKnownFolderName.Calendar,rooms[i].AccountName + "@company.com"); 
CalendarFolder calendar = CalendarFolder.Bind(service, CalendarFolderIdVal, new PropertySet()); 
更換線

CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); 

您應該只使用服務帳戶的電子郵件地址進行一次自動發現。

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

如果這個房間列表存在並且已經被填充,它將只返回該房間的EmailAddress在該列表中。該錯誤表明列表不存在。

Cheers Glen

相關問題