using (SPSite spSite = new SPSite("http://testsite"))
{
using (SPWeb objWeb = spSite.OpenWeb())
{
SPUser objUser = objWeb.EnsureUser("manuhsolutions\\samarendra");
SPList objLst = objWeb.Lists["ListName"];
SPListItem lstItem = objLst.GetItemById(1);
// break inheriting parent permissions for this List.
lstItem.BreakRoleInheritance(false);
// assign Role to the defined User
SPRoleDefinitionCollection objWebRoleDefn = objWeb.RoleDefinitions;
SPRoleAssignment objRoleAssign = new SPRoleAssignment(objUser);
// change the name of the role definition to [Contribute]
objRoleAssign.RoleDefinitionBindings.Add(objWebRoleDefn["Contribute"]);
lstItem.RoleAssignments.Add(objRoleAssign);
}
}
No comments:
Post a Comment