SharePoint 2013 - Update List Permissions with Client Object Model

The code below break permission inheritance of a list and add all authenticated users to have read permission level.

List list = rootWeb.Lists.GetByTitle("test");

list.BreakRoleInheritance(false, true);
RoleDefinition readerRole = clientContext.Web.RoleDefinitions.GetByType(RoleType.Reader);
RoleDefinitionBindingCollection rdb = new RoleDefinitionBindingCollection(clientContext);
rdb.Add(readerRole);
Principal usr = clientContext.Web.EnsureUser("NT Authority\\Authenticated Users");
test.RoleAssignments.Add(usr, rdb);
clientContext.ExecuteQuery();

If you want to user the "Everyone", you can use "c:0(.s|true" as the login name

Comments

Popular posts from this blog

SharePoint 2013 - Working with Display Template for Content Search Web Part

How to Customize MOSS Site Manager (Site Content and Structure Page)

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365