none
Finding Appointment by date and time using EWS Managed API 1.1 RRS feed

  • Question

  • Pretty self explanatory.

    I am using the EWS Managed API 1.1 to poll exchange about its appointments for the day so I can get a data table to populate. Picking out the information of the appointment to populate the table is fine as long as I know the ItemId but I don't.
    I presume there is someway to search for appointments by details (appt.Start) but I cannot for the life of me find reference to them.

    Any help greatly received.

    Friday, January 13, 2012 5:17 PM

Answers

  • Whenever your querying for Calendar appointments you should make use of the FindAppointments method and the calendarview class http://blogs.msdn.com/b/webdav_101/archive/2009/01/05/sample-using-calendar-views-with-ews.aspx the main reason for doing this is if you don't then any recurring appointments that you have within your calendar won't expand. You can't combine a CalendarView and a searchfilter so what you need to do for example is query from Items from today with a calendarview and then just filter out at the client side any of the appointments that you want based on whatever logic your looking for.

    Doing a FindItems would work for Single appointments but your searchfilter won't work because the StartDate is a DateTime datatype so the only valid search filter for that datatype would be IsEqual, GreaterThan,LessThan (from what i can see you also only have one condition for your Or collection)

    Cheers
    Glen 

    • Marked as answer by _Ritchie_ Wednesday, February 1, 2012 2:53 PM
    Tuesday, January 17, 2012 4:30 AM
  • Dim service As New ExchangeService(ExchangeVersion.Exchange2010)
                ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate()
                Dim UserCal as gObjIniFile.GetString("UserForReadingCalendars","")
    			Dim Password as gObjIniFile.GetString("PwdForReadingCalendars","")
    			Dim strDomain as gObjIniFile.GetString("WindowsDomain","")
                service.AutodiscoverUrl(UserName)
                service.Credentials = New NetworkCredential(UserCal, Password, strDomain)
                Dim appointment As New Microsoft.Exchange.WebServices.Data.Appointment(service)
    
                ' Setup Calendarview of appointments
                'DateTime format = year, month, day, hour, minute, second, kind.local
                Dim dtSlot As New DateTime(dDate.ToLongDateString, DateTimeKind.Local)  '' dDate need to be changed to fit new layout
                Dim dtEndDate As DateTime
                dtEndDate = dtSlot.AddHours(1)
                Dim calView As New CalendarView(dtSlot, dtEndDate, 30)      ' Maximum of 30 appointments in a day
    
                ' Get item(s) from calendar
                Dim findRes As FindItemsResults(Of Microsoft.Exchange.WebServices.Data.Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, calView)
    
                ' Use the results
                Dim apt As New Appt
                For Each Item In findRes
                    apt.appUID = Item.Id.ToString
                    apt.Subject = Item.Subject.ToString
                    apt.Description = Item.Body.ToString
                    apt.StartDate = Item.Start
                    apt.EndDate = Item.End
                    apt.Location = Item.Location.ToString
                    apt.Status = Item.LegacyFreeBusyStatus.ToString
                    apt.Instance = Item.AppointmentType.ToString
                    apt.Allday = Item.IsAllDayEvent.ToString
                    apt.RespReq = Item.IsResponseRequested
                Next

    This is not complaining at me yet which seems nice but I haven't tried to access the server to test yet
    • Edited by _Ritchie_ Tuesday, January 17, 2012 3:15 PM
    • Marked as answer by _Ritchie_ Friday, April 6, 2012 12:03 AM
    Tuesday, January 17, 2012 3:14 PM

All replies

  • Public Sub GetItemId(ByVal ldate As Long, ByVal ltime As Long)
                Dim lDateTime As Long
                lDateTime = ldate & " " & ltime
    
                ' Setup Exchange
                Dim service As New ExchangeService(ExchangeVersion.Exchange2010)
                ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate()
                Dim UserCal as gObjIniFile.GetString("UserForReadingCalendars","")
    			Dim Password as gObjIniFile.GetString("PwdForReadingCalendars","")
    			Dim strDomain as gObjIniFile.GetString("WindowsDomain","")
                service.AutodiscoverUrl(UserName)
                service.Credentials = New NetworkCredential(UserCal, Password, strDomain)
    
                ' Setup search
                Dim appointment As New Microsoft.Exchange.WebServices.Data.Appointment(service)
                Dim SFC As New List(Of SearchFilter)
                SFC.Add(New SearchFilter.ContainsSubstring(appointment.Start, lDateTime))
                Dim sF As SearchFilter = New SearchFilter.SearchFilterCollection(LogicalOperator.Or, SFC.ToArray())
                Dim view As New ItemView(50)
                Dim findRes As FindItemsResults(Of Microsoft.Exchange.WebServices.Data.Appointment) = service.FindItems(WellKnownFolderName.Calendar, sF, view)
    
                ' Use the results
                For Each appointment In findRes
                    Return appointment.ICalUid()
                Next()
    
            End Sub

    This is my current attempt for the situation.
    The date and time are arguments sent, calendar searched, from results the unique id is found.

    I know I'm missing something. Can anyone spot it/them?

    Monday, January 16, 2012 4:01 PM
  • Whenever your querying for Calendar appointments you should make use of the FindAppointments method and the calendarview class http://blogs.msdn.com/b/webdav_101/archive/2009/01/05/sample-using-calendar-views-with-ews.aspx the main reason for doing this is if you don't then any recurring appointments that you have within your calendar won't expand. You can't combine a CalendarView and a searchfilter so what you need to do for example is query from Items from today with a calendarview and then just filter out at the client side any of the appointments that you want based on whatever logic your looking for.

    Doing a FindItems would work for Single appointments but your searchfilter won't work because the StartDate is a DateTime datatype so the only valid search filter for that datatype would be IsEqual, GreaterThan,LessThan (from what i can see you also only have one condition for your Or collection)

    Cheers
    Glen 

    • Marked as answer by _Ritchie_ Wednesday, February 1, 2012 2:53 PM
    Tuesday, January 17, 2012 4:30 AM
  • Dim service As New ExchangeService(ExchangeVersion.Exchange2010)
                ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate()
                Dim UserCal as gObjIniFile.GetString("UserForReadingCalendars","")
    			Dim Password as gObjIniFile.GetString("PwdForReadingCalendars","")
    			Dim strDomain as gObjIniFile.GetString("WindowsDomain","")
                service.AutodiscoverUrl(UserName)
                service.Credentials = New NetworkCredential(UserCal, Password, strDomain)
                Dim appointment As New Microsoft.Exchange.WebServices.Data.Appointment(service)
    
                ' Setup Calendarview of appointments
                'DateTime format = year, month, day, hour, minute, second, kind.local
                Dim dtSlot As New DateTime(dDate.ToLongDateString, DateTimeKind.Local)  '' dDate need to be changed to fit new layout
                Dim dtEndDate As DateTime
                dtEndDate = dtSlot.AddHours(1)
                Dim calView As New CalendarView(dtSlot, dtEndDate, 30)      ' Maximum of 30 appointments in a day
    
                ' Get item(s) from calendar
                Dim findRes As FindItemsResults(Of Microsoft.Exchange.WebServices.Data.Appointment) = service.FindAppointments(WellKnownFolderName.Calendar, calView)
    
                ' Use the results
                Dim apt As New Appt
                For Each Item In findRes
                    apt.appUID = Item.Id.ToString
                    apt.Subject = Item.Subject.ToString
                    apt.Description = Item.Body.ToString
                    apt.StartDate = Item.Start
                    apt.EndDate = Item.End
                    apt.Location = Item.Location.ToString
                    apt.Status = Item.LegacyFreeBusyStatus.ToString
                    apt.Instance = Item.AppointmentType.ToString
                    apt.Allday = Item.IsAllDayEvent.ToString
                    apt.RespReq = Item.IsResponseRequested
                Next

    This is not complaining at me yet which seems nice but I haven't tried to access the server to test yet
    • Edited by _Ritchie_ Tuesday, January 17, 2012 3:15 PM
    • Marked as answer by _Ritchie_ Friday, April 6, 2012 12:03 AM
    Tuesday, January 17, 2012 3:14 PM

  •             For Each Item as Microsoft.Exchange.WebServices.Data.Appointment In findRes
                    apt.appUID = Item.Id.ToString
                    apt.Subject = Item.Subject.ToString
                    apt.Description = Item.Body.ToString
                    apt.StartDate = Item.Start
                    apt.EndDate = Item.End
                    apt.Location = Item.Location.ToString
                    apt.Status = Item.LegacyFreeBusyStatus.ToString
                    apt.Instance = Item.AppointmentType.ToString
                    apt.Allday = Item.IsAllDayEvent.ToString
                    apt.RespReq = Item.IsResponseRequested
                Next
    


    Better format for processing however the body needs to be done differently if you wish to get that information.

    Dim body As New PropertySet(BasePropertySet.FirstClassProperties)
    body.Add(ItemSchema.Body)
    Appt.Load(body)

     

    • Edited by _Ritchie_ Wednesday, February 1, 2012 3:28 PM
    Wednesday, February 1, 2012 2:55 PM