How to assign unique permission to Sharepoint list or library in Sharepoint 2016/2013 or office 365?

Hello Sharepointers,

In this blog, I will explain about assigning unique permissions to sharepoint list or library using CSOM Code.

public static void AddUniquePermission(ClientContext ctx, List slist,
string groupName, string permissionName)
{

var GroupName= ctxWeb.SiteGroups.GetByName(groupName);
var roletypes=ctxWeb.RoleDefinitions.GetByType(RoleType.Contributor);
ctx.ExecuteQuery();
slist.BreakRoleInheritance(true, false);
RoleDefinitionBindingCollection collRoleDefinitionBinding =
new RoleDefinitionBindingCollection(ctx);
collRoleDefinitionBinding.Add(roletypes);
slist.RoleAssignments.Add(GroupName, collRoleDefinitionBinding);
ctx.ExecuteQuery();
}

Hope the above code snippet helps you guys. Happy Sharepointing guys!!

Leave a Reply

Your email address will not be published.