Exchange EWS API .NET - CalendarEvents.Details始终为null

时间:2013-01-04 14:01:59

标签: .net exchange-server exchangewebservices

我正在尝试构建一个.NET应用程序,目的是从交换帐户中检索日历信息。我想检索有关资源的忙/闲信息。 我将EWS .NET API与Exchange 2010连接一起使用。

我可以检索约会的StartTime和EndTime等信息,但是我无法获得其他信息,例如主题,CalendarEvents.Details中包含的位置。实际上,最后一个属性始终为null。 显然它可能是一个权限问题,但它不符合逻辑,因为我尝试用自己的凭据阅读我自己的日历。

//Exchange Connection
this.service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials(user, password, domain);
service.AutodiscoverUrl(this.email);


 List<AttendeeInfo> attendees = new List<AttendeeInfo>();

 //L'utilisateur déclaré dans l'objet, identifié par l'email
 attendees.Add(new AttendeeInfo()
 {
    SmtpAddress = this.email,
    AttendeeType = MeetingAttendeeType.Organizer
  });

 AvailabilityOptions myOptions = new AvailabilityOptions();
 myOptions.MeetingDuration = 30;
 myOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;


 GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
                                                                             new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1)),
                                                                                 AvailabilityData.FreeBusy,
                                                                                 myOptions);



  foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
        {

         foreach (CalendarEvent calendarItem in availability.CalendarEvents)
         {
             //The details here are always null :/          
            if (calendarItem.Details != null)
             {
               label3.Text = "Subject: " + calendarItem.Details.Subject +"\n";
               label3.Text += " Location:" + calendarItem.Details.Location ;
             }


             label3.Text += "\n";
             label3.Text += "Start:" + calendarItem.StartTime.TimeOfDay ;
             label3.Text += "End:" + calendarItem.EndTime.TimeOfDay;
             label3.Text += "\n";
             panel1.BackColor = Color.PaleVioletRed;
             break;       
         }
    }

提前谢谢你,

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,可能使用了相同的示例代码。问题出在您的可用性选项的FreeBusyViewType

myOptions.RequestedFreeBusyView = FreeBusyViewType.Detailed;

Link to MSDN Documentation