Assign list level permission using client object model


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Client;
namespace
ClientObjectModel
{
class Program
{
static void Main(string[] args)
{

//Assign list level permission using client object model

string siteURL = "http://serverName:1111/sites/SPSiteDataQuery/";
ClientContext context = new ClientContext(siteURL);
List list = context.Web.Lists.GetByTitle("Shared documents");
User user=context.Web.EnsureUser(@"DomainName\UserName");
list.BreakRoleInheritance(
true,false);
RoleDefinition roleDefinition=context.Web.RoleDefinitions.GetByName("Custom Permission Level");
RoleDefinitionBindingCollection collRoleDefinitionBinding = new RoleDefinitionBindingCollection(context);
collRoleDefinitionBinding.Add(roleDefinition);
list.RoleAssignments.Add(user,collRoleDefinitionBinding);
context.ExecuteQuery();

}
}
}