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 App Details Page Error

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

SharePoint 2013 Features Information List