none
EWS - Get phone number RRS feed

  • Question

  • Hi all!
    I'm new to ews development and i'm trying to query exchange for all appointments on the current day, and i have two problems.

    1. Code works fine, i can get the appointments and their subjects but it's kinda slow, which makes me wonder if i'm loading too
    many properties or doing something else that's unnecessary. Perhaps there is a better and faster way to do it=

    2. I need to get the phone number of the person (attendee) invited to the appointment.

    Any suggestions?

    [code]


            Dim service = New ExchangeService(ExchangeVersion.Exchange2010_SP1)
            Dim credential As New NetworkCredential("user", "pass", "domain")
            Dim Url = New Uri("https://MyServer/EWS/Exchange.asmx")
            Dim prop As New PropertySet(BasePropertySet.FirstClassProperties)

            service.Url = Url
            service.Credentials = credential

            Dim calendar As CalendarFolder = Folder.Bind(service, WellKnownFolderName.Calendar)
            Dim results = calendar.FindAppointments(New CalendarView(Now, Now))

            For Each appt As Appointment In results
                If appt.Subject.Contains("TEST") Then
                    appt.Load(prop)
                    ListBox1.Items.Add(appt.Subject & " - " & appt.Start & " - " & appt.End)
                    For Each attend As Attendee In appt.RequiredAttendees
                        ListBox1.Items.Add(attend.Address)
                    Next
                    Exit For
                End If
            Next

    [/code]

    Thursday, December 8, 2011 10:42 AM

All replies

  • 1. You need to first investigate what is "Kinda Slow" eg your code is making multiple request the first is its doing a FindItems request with a calendar View which means its expanding recurrences etc then its making a GetItem request to get the attendees (appt.Load(prop)). So you need to debug your code to work out where you think its spending too much time. To speed things up define a property set to use for FindAppointments operation and specify just BasePropertySet.IdOnly and the Subject property this will the results set that is returned. Similar with the Load just define in the propertySet which props you are going to use if your loading more the one Item then use http://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.loadpropertiesforitems(v=exchg.80).aspx which will reduce the number of GetItem requests you need to make to the server.

    2. The only way of getting the phone number would be to use a ResolveName operation on each of the attendees and pull the AD information (if the phone number has been set) (which is going to be a little slow if you have a lot of attendees eg)

               NameResolutionCollection ncCol = service.ResolveName("user@domain.com",ResolveNameSearchLocation.DirectoryOnly,true);
               Console.WriteLine(ncCol[0].Contact.PhoneNumbers[PhoneNumberKey.BusinessPhone]);
    

     

    Cheers
    Glen

     

     

    Friday, December 9, 2011 4:17 AM
  • Thanks Glen!

    I'll look into defining a more specific property set and see what happens. Regarding the phone number i ended up making LDAP query using the display name of the attendee instead. Works like a charm and also quite fast.

    Friday, December 9, 2011 10:59 AM