我有一个要求,例如我需要使用 Exchange 服务 API 中的管理员帐户获取所有用户日历事件。我尝试过但无法实现,因此请就此提供建议。PFB 代码供您参考。我正在使用 Exchange 服务器版本 2013_SP1。在下面的代码中,我只能获取一个用户日历事件的详细信息。
public List<EWSModel> GetCalendarEventDetails()
{
List<EWSModel> objCalItems = new List<EWSModel>();
try
{
ExchangeService service = CallEWSAPIService();
DateTime startDate = DateTime.Now.AddDays(-30);
DateTime endDate = DateTime.Now;
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cView = new CalendarView(startDate, endDate);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
EWSModel objModel = null;
foreach (Appointment appItem in appointments)
{
appItem.Load();
List<string> attendees = new List<string>();
foreach (var emailItem in appItem.RequiredAttendees)
{
attendees.Add(emailItem.Name);
}
objModel = new EWSModel();
objModel.AppointmentTitle = appItem.Subject.ToString();
objModel.Subject = appItem.Subject.ToString();
objModel.Body = StripHTML(appItem.Body.Text).Replace("\r", "").Replace("\n", "");
objModel.EmailAddress = attendees;
objModel.Location = appItem.Location.ToString();
objModel.StartDate = appItem.Start;
objModel.EndDate = appItem.End;
objCalItems.Add(objModel);
}
}
catch (Exception err)
{
throw err;
}
return objCalItems;
}