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);
slist.BreakRoleInheritance(true, false);
RoleDefinitionBindingCollection collRoleDefinitionBinding =
new RoleDefinitionBindingCollection(ctx);
slist.RoleAssignments.Add(GroupName, collRoleDefinitionBinding);

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

Leave a Reply

Your email address will not be published. Required fields are marked *