none
Find appointments in Exchange Server RRS feed

  • Question

  • Hello All,

    I am trying to find the appointments by passing the start date and time and end date and time. But I am not getting appointments exactly as per passed start date and end date.

    Below is my code

     ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Credentials = new NetworkCredential("my email address", "my password");
                service.PreAuthenticate = true;
                //service.SendClientLatencies = true;
                //service.EnableScpLookup = false;
                service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
                service.TraceEnabled = true;
                service.TraceFlags = TraceFlags.All;
    
                DateTime startDate = DateTime.Now;
                DateTime endDate = startDate.AddDays(30);
                const int NUM_APPTS = 5;
    
                // Initialize the calendar folder object with only the folder ID. 
                CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
    
                // Set the start and end time and number of appointments to retrieve.
                CalendarView cView = new CalendarView(startDate, endDate);
    
                // Limit the properties returned to the appointment's subject, start time, and end time.
                cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id,  AppointmentSchema.DateTimeCreated);
                
                // Retrieve a collection of appointments by using the calendar view.
                FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
    
                Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + startDate.Date.ToShortDateString() +
                                  " to " + endDate.Date.ToShortDateString() + " are: \n");
    
                foreach (Appointment a in appointments)
                {
                    Console.Write("Subject: " + a.Subject.ToString() + " ");
                    Console.Write("Start: " + a.DateTimeCreated.ToString() + " ");
                    Console.Write("Start: " + a.Start.ToString() + " ");
                    Console.Write("End: " + a.End.ToString());
                    Console.Write("AppointmentID: " + a.Id.ToString());
    
                    Console.WriteLine();
                }

    If start date is 09-jan-2015 with time 3.00 pm.; Still it is giving me appointment for the same date which starts at 9.00 am

    Why this is so ? How should we specify the date and time to get the correct appointments


    Friday, January 9, 2015 12:15 PM

All replies

  • Most likely the problem is time zones. You don't specify any time zone, so times are all considered as the local time zone of the machine where you're running your code. If the user's time zone is something different, you may introduce some confusion.

    You can check yourself by looking at the traces and seeing what values are passed in the CalendarView element. These will be in UTC (converted from your local time zone).

    Friday, January 9, 2015 3:18 PM
    Moderator
  • Most likely the problem is time zones. You don't specify any time zone, so times are all considered as the local time zone of the machine where you're running your code. If the user's time zone is something different, you may introduce some confusion.

    You can check yourself by looking at the traces and seeing what values are passed in the CalendarView element. These will be in UTC (converted from your local time zone).

    Can you give me some example of this ? Still, I am not able to get the appointment as per the specified date and time ?

    Thursday, January 15, 2015 1:16 PM
  • http://msdn.microsoft.com/EN-US/library/office/dn789029(v=exchg.150).aspx is a good place to start. I'd recommend enabling tracing and seeing what goes on the wire.
    Friday, January 16, 2015 5:55 PM
    Moderator