I would like to get all appointments which are in a certain date range from my coworker by his email. I can access his calendar through outlook. I only want to know if he has set an appointment as "Free", "Busy" or "OOF". The code works with "Full Details" permission, but not with the "Free / Busy time, subject, location" permission level.
My coworker shouldn't change the permission level to "Full details". It should stay on "Free/Busy time, subject, location" like this:
I have the following code:
private static void GetAllCalendarItems()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.UseDefaultCredentials = true;
service.Url = new Uri("https://example.com/EWS/Exchange.asmx");
FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "coworker@mexample.com");
Folder TargetFolder = Folder.Bind(service, cfolderid);
CalendarFolder calendar = CalendarFolder.Bind(service, cfolderid);
CalendarView cView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(30), 5);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.LegacyFreeBusyStatus);
FindItemsResults<Appointment> appointments = null;
try
{
appointments = calendar.FindAppointments(cView);
}
catch (ServiceResponseException ex)
{
Debug.WriteLine("Error code: " + ex.ErrorCode);
Debug.WriteLine("Error message: " + ex.Message);
Debug.WriteLine("Response: " + ex.Response);
}
foreach (Appointment a in appointments)
{
Debug.Write("Subject: " + a.Subject.ToString() + "\t\t\t");
Debug.Write("Status: " + a.LegacyFreeBusyStatus.ToString() + "\t\t\t");
Debug.WriteLine("");
}
}
This code works fine with my email. But not with the one from my coworker. I get the following exception in my try-catch-block:
Exception thrown: 'Microsoft.Exchange.WebServices.Data.ServiceResponseException' in Microsoft.Exchange.WebServices.dll
Error code: ErrorAccessDenied
Error message: Access is denied. Check credentials and try again.
Response: Microsoft.Exchange.WebServices.Data.FindItemResponse`1[Microsoft.Exchange.WebServices.Data.Appointment]
I have access to his calendar with the given permissions, because I can see his appointments in outlook, so how can I get the appointments with the status from my coworker by his email?