none
Gettings contacts inside a contact group RRS feed

  • Question

  • Hi:

    I am developing a internal app to surface contacts of all our employees. We are running Exchange 2010. I am able to get everyone's "default" contacts however I am not able to get contacts that are inside a custom contact group. Here is my code. 

     FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Contacts, new ItemView(Int32.MaxValue));
    
                        foreach (var item in findResults.Items)
                        {
                            if (item.GetType() == typeof(Microsoft.Exchange.WebServices.Data.Contact))
                            {
                                var contact = item as Microsoft.Exchange.WebServices.Data.Contact;
                                if (!String.IsNullOrEmpty(contact.DisplayName))
                                    Console.WriteLine(contact.DisplayName);
                                else
                                    Console.WriteLine(contact.CompanyName);
                            }
                            else if (item.GetType() == typeof(Microsoft.Exchange.WebServices.Data.ContactGroup))
                            {
                                var contactGroup = item as Microsoft.Exchange.WebServices.Data.ContactGroup;
                                Console.WriteLine("Group Name: " + contactGroup.DisplayName);
                                foreach (GroupMember member in contactGroup.Members)
                                {
                                    Console.WriteLine(member.AddressInformation.Name);
                                }
                            }
                        }



    Kemal Tolga Koseoglu Application Developer WATG

    Wednesday, August 8, 2012 1:04 AM

All replies

  • You need to call load (which will do a GetItem request) and load the Members collection as this isn't returned in a FindItemRequest

    eg

    var contactGroup = item as Microsoft.Exchange.WebServices.Data.ContactGroup;
    contactGroup.Load();
    Cheers
    Glen
    Wednesday, August 8, 2012 6:18 AM