Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Find appointments in Exchange Server

$
0
0

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



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>