grab a distribution list in the public folders using EWS

I work in a small office that has an Exchange 2013 server.  We would like to be able (vb or C# code would be great) query a distribution list called ListA from the public folders/Office Contacts. So under public folders there is another folder called Office Contacts. In that office contacts is where ListA distribution list lives. We want to get a listing of all the contacts that belong to that ListA. We would like to use EWS to do this as the results will be displayed to an internal web page. I've tried like crazy to figure out how to do this but have not had any luck getting any further than the Office Contacts. Can someone please point me in the right direction. I've got EWS 2.0 on the web project. I would post code but i'm not sure what I have would be of any value.

Thanks

Shannon

July 23rd, 2015 2:22pm

It should be relatively simple, Distribution Lists are stored in Contact Folders aren't called DL's they are called Contact Groups. So all you need to do is Find the Folder first, Find the list (search by name), Load the Members and enumerate eg

            //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) {
                    Console.WriteLine(gm.AddressInformation.Address);
                }
            }
Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 23rd, 2015 9:38pm

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

Other recent topics Other recent topics