fetch contact information from a public folders contact

Thanks to a helpful person on this list I have the name and email address from the public folders.  That information is in a GroupMemeber object.  What I can not get working now is how to take that information and query the public folder for all the information for that contact.  From the Group Member you can get the persons name and email address but I also need the title, company, address and phone.  I've tried to modify the code to query the info I need but have not had success.  I'm using EWS 2.0.  Can someone point me in the right direction please.

thanks

**********

I'm not sure where i'm really suppose to search. Do you search Contact.Schema.EmailAddress1 or does it have to be something from the public folders.. it couldn't be FolderSchema but I didn't see anything else I should be searching on.. anyway..

**********

making some progress.  I'm now able to get to the contact information by passing in the email address..

Here is the code in case it can help someone else out

 Dim sf As SearchFilter = New SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Office Contacts")
        Dim rrRes As FindFoldersResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, sf, New FolderView(1))
        Dim OfficeContacts As Folder = rrRes.Folders(0)
        'Find the Distribution List
        Dim dlSearch As SearchFilter = New SearchFilter.IsEqualTo(ContactSchema.EmailAddress1, "thename@outlook.com")
        Dim ivItemView As New ItemView(1)
        Dim fiResults As FindItemsResults(Of Item) = OfficeContacts.FindItems(dlSearch, ivItemView)
        If fiResults.Items.Count = 1 Then

            Dim con As Contact = fiResults.Items(0)



            'Enumeate Members
            Dim cg As ContactGroup = DirectCast(fiResults.Items(0), ContactGroup)
end if

  • Edited by jvcoach23 Friday, July 24, 2015 6:00 PM
July 24th, 2015 3:22pm

This really depends on the what is in the ContactsGroup eg a Contact Group member maybe a entry in the Global Address List, a Local Contact Folder entry or possible a Contract from that or another public folder.

If all the Contacts that are in the ContactGroup are also in the Folder when the ContactGroup is located then you should just be able to use

            //Get Public Folder
            SearchFilter sf = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Office Contacts");
            FindFoldersResults rrRes =  service.FindFolders(WellKnownFolderName.PublicFoldersRoot, sf, new FolderView(1));
            Folder OfficeContacts = rrRes.Folders[0];

            //Find the Distribution List
            SearchFilter dlSearch = new SearchFilter.IsEqualTo(ContactGroupSchema.DisplayName, "My List");
            ItemView ivItemView = new ItemView(1);
            FindItemsResults<Item> fiResults = OfficeContacts.FindItems(dlSearch, ivItemView);
            if (fiResults.Items.Count == 1) { 
                //Enumeate Members
                ContactGroup cg = (ContactGroup)fiResults.Items[0];
                cg.Load();
                foreach (GroupMember gm in cg.Members) {
                    SearchFilter sfe = new SearchFilter.IsEqualTo(ContactSchema.EmailAddress1, gm.AddressInformation.Address);
                    FindItemsResults<Item> fiItems = service.FindItems(OfficeContacts.Id, sfe, new ItemView(1));
                    if (fiItems.Items.Count == 1)
                    {
                        Contact centry = (Contact)fiItems.Items[0];
                        centry.Load();
                        Console.WriteLine(centry.CompanyName);
                    }
                    Console.WriteLine(gm.AddressInformation.Id);                
                }
            }

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 12:41am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics