public static void Setpermission(SPWeb subWeb, SPListItem lstItm)
{
bool status= true;
SPRoleAssignmentCollection spRoleAssignmentCol = lstItm.RoleAssignments;
foreach (SPRoleAssignment sprol in spRoleAssignmentCol)
{
if (sprol.Member.Name == "Directors")
{
status = false;
}
}
if (status)
{
if (!lstItm.ParentList.HasUniqueRoleAssignments)
{
lstItm.ParentList.BreakRoleInheritance(true);
}
SPGroup sgroup = lstItm.Web.Groups["Directors"];
// set unique permissions for listitem. Current user will automatically get full control
lstItm.BreakRoleInheritance(false);
SPRoleAssignment spRoleAssignment = new SPRoleAssignment(sgroup);
//SPRoleDefinition spRoleDefinition = elevatedWeb.RoleDefinitions[LocalizationStrings.NewProject.NewProjectStrings.ContributePermission];
SPRoleDefinition spRoleDefinition = lstItm.Web.RoleDefinitions["Contribute"];
if (!spRoleAssignment.RoleDefinitionBindings.Contains(spRoleDefinition))
spRoleAssignment.RoleDefinitionBindings.Add(spRoleDefinition);
lstItm.RoleAssignments.Add(spRoleAssignment);
subWeb.RoleAssignments.Add(spRoleAssignment);
subWeb.Update();
}
}
{
bool status= true;
SPRoleAssignmentCollection spRoleAssignmentCol = lstItm.RoleAssignments;
foreach (SPRoleAssignment sprol in spRoleAssignmentCol)
{
if (sprol.Member.Name == "Directors")
{
status = false;
}
}
if (status)
{
if (!lstItm.ParentList.HasUniqueRoleAssignments)
{
lstItm.ParentList.BreakRoleInheritance(true);
}
SPGroup sgroup = lstItm.Web.Groups["Directors"];
// set unique permissions for listitem. Current user will automatically get full control
lstItm.BreakRoleInheritance(false);
SPRoleAssignment spRoleAssignment = new SPRoleAssignment(sgroup);
//SPRoleDefinition spRoleDefinition = elevatedWeb.RoleDefinitions[LocalizationStrings.NewProject.NewProjectStrings.ContributePermission];
SPRoleDefinition spRoleDefinition = lstItm.Web.RoleDefinitions["Contribute"];
if (!spRoleAssignment.RoleDefinitionBindings.Contains(spRoleDefinition))
spRoleAssignment.RoleDefinitionBindings.Add(spRoleDefinition);
lstItm.RoleAssignments.Add(spRoleAssignment);
subWeb.RoleAssignments.Add(spRoleAssignment);
subWeb.Update();
}
}
No comments:
Post a Comment