2

I want to copy a SharePoint Permissions Groups to subsites that does not have that group already. The permissions inheritance is broken.

Lets say we have the following site structure:

https://x.sharepoint.com/SubsiteLevel1/
https://x.sharepoint.com/SubsiteLevel1/SubsiteLevel2/

How would I go about getting the site specific Groups that are used on SubsiteLevel2 (or any site). The problem I am facing is that when I get the Groups from a site I can only get the SiteGroups. So all groups on the Site Collection.

GroupCollection groupCollection = web.SiteGroups;

How can I get the specific groups that are used on a sub site?

1 Answer 1

1

You can get it via the RoleAssignmentCollection.Groups property.

Check the below code:

using (ClientContext context = new ClientContext("site-collection-url"))
{   
    //pass the sp web 
    Web oWeb = context.Site.OpenWeb("SubsiteLevel1");
    context.Load(oWeb);
    context.ExecuteQuery();

    var groups = oWeb.RoleAssignments.Groups;
    context.Load(groups);
    context.ExecuteQuery();

    foreach(Microsoft.SharePoint.Client.Group group in groups)
    {                    
        Console.WriteLine(group.Title);
    }   

}

To get the 2nd level subsite groups, replace the

context.Site.OpenWeb("SubsiteLevel1");

to below (use the server-relative url of the sp web):

context.Site.OpenWeb("SubsiteLevel1/SubsiteLevel2");

MSDN - RoleAssignmentCollection.Groups property

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.