locked
specific users in site group RRS feed

  • Question

  • I have a site collection and it has a 3 custom sharepoint groups (Admins, members, readers). It has a set of specific users.

    We also 4 subsites (spWeb) in this Site Collection with same custom sharepoint groups (Admins, members, readers).

    I wanted to add specific users to Subsite group and not wanted to reflect in the site collection groups. How to do it using sharepoint object model code.

    when I execute the following code

    SPWeb web = <>;

    SPGroup grp = web.SiteGroups["Admins"];

    grp.AddUser("username","","");

    Its adding users to site collection (SPSite) level. I need it to add in site (SPWeb) level. How to do it?

    Tuesday, May 22, 2012 12:07 AM

Answers

  • Sharepoint Groups are created in SharePoint Site Collection context.

    So when the users are added into SharePoint Groups  will be reflected everywhere. so add specific subsite level groups after setting the Unique permissions.

    For Eg: If you have 2 SharePoint groups (Admins, CommonUsers) at site collection level, when users added to these groups from anywhere (from top level site or sub siites) in the site collection will be reflected everywhere. You are advised to set unique permissions to subsite, then add sub site level groups  (SubSite1 Admins, SubSite1 CommonUsers) and add users to those groups.

    Saturday, May 26, 2012 2:19 AM

All replies

  • Groups are defined / exist at the Site Collection level. If you need different group members in a subsite then you will need to create a new group for that subsite.

    The subsite will also need unique permissions, either by being created with unique permissions or by breaking inheritance. You can see SharePoint doing this when you create a new subsite and select Unique Permissions. It will create new groups with names like "subsitename Owners", "subsitename Members", etc.


    Mike Smith TechTrainingNotes.blogspot.com

    • Proposed as answer by Nazre1 Tuesday, May 22, 2012 3:49 AM
    Tuesday, May 22, 2012 1:55 AM
  • On top of Mike Smith's response, you need to use the following to get the local group in that SPWeb.

    web.Groups["GroupName"];

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.groups.aspx


    Allen Wang | http://blogs.msdn.com/allenwang

    Tuesday, May 22, 2012 3:39 AM
  • Sharepoint Groups are created in SharePoint Site Collection context.

    So when the users are added into SharePoint Groups  will be reflected everywhere. so add specific subsite level groups after setting the Unique permissions.

    For Eg: If you have 2 SharePoint groups (Admins, CommonUsers) at site collection level, when users added to these groups from anywhere (from top level site or sub siites) in the site collection will be reflected everywhere. You are advised to set unique permissions to subsite, then add sub site level groups  (SubSite1 Admins, SubSite1 CommonUsers) and add users to those groups.

    Saturday, May 26, 2012 2:19 AM