Get SharePoint group list for a user - InfoPath Dev
in

InfoPath Dev

Get SharePoint group list for a user

Last post 08-17-2011 07:23 AM by DC-jeff. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-16-2011 12:45 PM

    Get SharePoint group list for a user

    Have a requirement to determine which SharePoint groups a user is a member of in order to control content on an IP form.  Have looked at DBXL at Active Directory Service but found that this only allows me to determine membership against Active Directory groups not SharePoint groups. This is a non starter since I don't control AD groups and don't have the ability to add/remove people as needed. Have also looked at various methods within the SharePoint webservice UserGroup.asmx and UserProfileService.asmx and not found anything that works out of the box without significant modification of the XML (i.e. GetUserCollectionFromGroup).  Any thoughts on how to support this requirement?

    thanks

    Jeff

  • 08-16-2011 01:28 PM In reply to

    Re: Get SharePoint group list for a user

    Hi Jeff,

    by using the SPUser.Groups property you can easily enumerate the groups that a user has been assigned to. You can check whether a particular user is a member of the SharePoint group or not, taking into account AD group membership with using the SPGroup.ContainsCurrentUser property as shown below:

            private bool CheckGroupMembership(string spGroupName)
            {
               try
               {
                  // Definition Web and website
                  using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                  {
                     SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
                     SPGroup checkGroup = web.Groups[spGroupName];
                     if (checkGroup != null)
                     {
                         return checkGroup.ContainsCurrentUser;
                     }
                         else { return false; }
                     }
                  }
                  catch (Exception ex)
                  {
                     return false;
                  }
               }
            }

    Hope that helps.

    Regards,

    Karsten
  • 08-17-2011 07:23 AM In reply to

    Re: Get SharePoint group list for a user

    Thanks Karsten. Any code free options that you're aware of?

    Jeff

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.