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