I have a requirement like I need to fetch all the users calendar events using an Admin account in Exchange service API.I tried but I am unable to achieve it so Please advise me on this. PFB code for your reference. I am using Exchange server Version 2013_SP1. In the below code I can able to get only one user calendar event details.
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;
}