0

Currently I am having a requirement to get Active Directory Group List for current logged in user.

I tried with :

/_vti_bin/UserProfileService.asmx

/_vti_bin/UserGroup.asmx

I am only able retrieve SharePoint Groups.

Quick reply will be high appreciated as this an urgent FIX.

Thank you

  • Is this SharePoint Online or SharePoint on-premises? If on-premises, which version? – Rob Windsor Apr 18 at 10:42
  • on-premises and 15.0 – mzonerz Apr 18 at 11:04
0

SharePoint does not provide a web service to get Active Directory group information. The only way I'm aware of to get this information in InfoPath is for you to create a custom web service that would provide it.

If you wish to build the custom web service then you should be able to use code similar to the code below to get the UserPrincipal for the current user. Once you do you can call the GetGroups method to find out the groups to which they belong.

using System.DirectoryServices.AccountManagement;  

protected bool CurrentUserIsMemberOfGroup(string groupName)  
{  
    string userLogin = SPContext.Current.Web.CurrentUser.LoginName;  
    // To get the right context, run with elevated privileges  
    SPSecurity.RunWithElevatedPrivileges(delegate()   
    {  
        var principalContext = new PrincipalContext(ContextType.Domain);  
        var userPrincipal = UserPrincipal.FindByIdentity(principalContext, System.DirectoryServices.AccountManagement.IdentityType.SamAccountName, userLogin);  
        var group = GroupPrincipal.FindByIdentity(principalContext , groupName);  
        return userPrincipal.IsMemberOf(group);   
    });  
} 

For more information on getting information from Active Directory please see Check if a SharePoint user is member of an AD group, Retrieve the Active Directory groups of the current user, and UserPrincipal Class

For more information on building and deploying a custom web service please see Building a SharePoint-Hosted WCF Service

  • Thank you rob, Are we able get Distribution List Group in this way? So far I have seen only AD groups not Distribution Groups..confusing! – mzonerz Apr 18 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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