我正在尝试构建一个 .NET 应用程序,其目的是从 Exchange 帐户检索日历信息。我想检索有关资源的忙/闲信息。 我将 EWS .NET API 与 Exchange 2010 连接结合使用。
我可以检索约会的 StartTime 和 EndTime 等信息,但无法获取 CalendarEvents.Details 中包含的主题、位置等其他信息。事实上,最后一个属性始终为空。 显然这可能是权限问题,但这不合逻辑,因为我尝试用自己的凭据读取自己的日历。
//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;
}
}
提前谢谢您,
最佳答案
我遇到了同样的问题,可能使用了相同的示例代码。问题出在您的可用性选项的 FreeBusyViewType
myOptions.RequestedFreeBusyView = FreeBusyViewType.Detailed;
关于.net - Exchange EWS API .NET - CalendarEvents.Details 始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14158609/