0

I want to fetch the AD group users in SharePoint. Below is the code where i can get the SharePoint group. but how can we get AD group

 private SPFieldUserValueCollection GetPeopleFromPickerControl(PeopleEditor people, SPWeb web)
        {
            SPFieldUserValueCollection values = new SPFieldUserValueCollection();
            if (people.ResolvedEntities.Count > 0)
            {
                for (int i = 0; i < people.ResolvedEntities.Count; i++)
                {
                    PickerEntity user = (PickerEntity)people.ResolvedEntities[i];
                    switch ((string)user.EntityData["PrincipalType"])
                    {
                        case "User":
                            SPUser webUser = web.EnsureUser(user.Key);
                            SPFieldUserValue userValue = new SPFieldUserValue(web, webUser.ID, webUser.Name);
                            values.Add(userValue);
                            break;

                        case "SharePointGroup":
                            SPGroup siteGroup = web.SiteGroups[user.EntityData["AccountName"].ToString()];
                            SPFieldUserValue groupValue = new SPFieldUserValue(web, siteGroup.ID, siteGroup.Name);
                            values.Add(groupValue);
                            break;
                    }
                }
            }
            return values;
        }

1 Answer 1

1

An AD Group is actually just another type of SPUser object. The SPUser object has the property IsDomainGroup which will be set to true if it is an AD group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.