Code
//判断是否是自定义权限
if (item.HasUniqueRoleAssignments)
{
web.AllowUnsafeUpdates = true;
//恢复权限
item.ResetRoleInheritance();
}
else
{
//自定义权限
web.AllowUnsafeUpdates = true;
//TRUE:取父级的权限;FALSE:清除所有权限
item.BreakRoleInheritance(false);
//添加一个人权限
SPRoleAssignment ra1 = new SPRoleAssignment(user);
ra1.RoleDefinitionBindings.Add(web.RoleDefinitions["读取"]);
web.AllowUnsafeUpdates = true;
item.RoleAssignments.Add(ra1);
//添加一个组权限
SPRoleAssignment ra2 = new SPRoleAssignment(web.Groups["SpsExpertAdmins"]);
ra2.RoleDefinitionBindings.Add(web.RoleDefinitions["读取"]);
web.AllowUnsafeUpdates = true;
item.RoleAssignments.Add(ra2);
}
//判断是否是自定义权限
if (item.HasUniqueRoleAssignments)
{
web.AllowUnsafeUpdates = true;
//恢复权限
item.ResetRoleInheritance();
}
else
{
//自定义权限
web.AllowUnsafeUpdates = true;
//TRUE:取父级的权限;FALSE:清除所有权限
item.BreakRoleInheritance(false);
//添加一个人权限
SPRoleAssignment ra1 = new SPRoleAssignment(user);
ra1.RoleDefinitionBindings.Add(web.RoleDefinitions["读取"]);
web.AllowUnsafeUpdates = true;
item.RoleAssignments.Add(ra1);
//添加一个组权限
SPRoleAssignment ra2 = new SPRoleAssignment(web.Groups["SpsExpertAdmins"]);
ra2.RoleDefinitionBindings.Add(web.RoleDefinitions["读取"]);
web.AllowUnsafeUpdates = true;
item.RoleAssignments.Add(ra2);
}