2015-04-08 77 views
1

我目前正在開發一個應用程序,該應用程序檢查一個或多個用戶日曆是否在特定類別下的約會/會議。Exchange EWS Api - 按類別獲取日曆預約

作爲EWS的新手,我一直在努力尋找解決方案,以按類別獲取日曆項目(預約或會議),或確定約會是否具有特定類別。到目前爲止,我目前有以下代碼(exService = ExchangeService對象):

foreach (Appointment a in exService.FindItems(WellKnownFolderName.Calendar, new ItemView(int.MaxValue))) 
      { 
       //Need to check if appointment has category f.x.: "SMS" 
      } 

有沒有人知道一種方法實現此目的?

感謝

回答

3

當你想使用FindAppointments您的查詢預約及壓延視圖而不是使用FindItems這將確保任何定期約會被擴展如見https://msdn.microsoft.com/en-us/library/office/dn495614(v=exchg.150).aspx

使用類別所有你需要do就像

 DateTime startDate = DateTime.Now; 
     DateTime endDate = startDate.AddDays(60); 
     const int NUM_APPTS = 1000; 

     // Initialize the calendar folder object with only the folder ID. 
     CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); 

     // Set the start and end time and number of appointments to retrieve. 
     CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS); 

     // Limit the properties returned to the appointment's subject, start time, and end time. 
     cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End,AppointmentSchema.Categories); 

     // Retrieve a collection of appointments by using the calendar view. 
     FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView); 

     Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() + 
          " to " + endDate.Date.ToShortDateString() + " are: \n"); 
     foreach (Appointment a in appointments) 
     { 
      if (a.Categories.Contains("Green")) 
      { 
       Console.Write("Subject: " + a.Subject.ToString() + " "); 
       Console.Write("Start: " + a.Start.ToString() + " "); 
       Console.Write("End: " + a.End.ToString()); 
      }     
      Console.WriteLine(); 
     }