Search code examples
sharepointsharepoint-2010

Programmatically break permission level inheritance


I would like to create a subsite that has its own custom Permission Levels. At the moment, when I visit the Permission Levels screen at http://servername/subsite1/_layouts/role.aspx I see all the permission levels but these are ones from the rootweb. How can I break the inheritance here and add my own custom permission level?

The purpose is because the role would have no use outside of this site so I would prefer not to put it on the root.

This question is the same as asked here: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/32ad2700-8009-4636-880e-07acfca98a06 but Shah Mehul replied saying it could be done programmatically. Is he mistaken? I've read through the parameter descriptions at SPWeb.BreakRoleInheritance(Boolean, Boolean) but they don't describe Permission Levels.


Solution

  • You can still break permission level inheritance in sharepoint 2010, albeit only programatically (reference: http://technet.microsoft.com/en-us/library/ff607713.aspx , section Permissions for sub-webs)

    To break it programmatically you can use the SPRoleDefinitionCollection.BreakInheritance Method (http://msdn.microsoft.com/en-us/library/ee547386.aspx)

    Powershell sample:

    $web = Get-SPWeb "your site URL"
    $web.RoleDefinitions.Delete("Some Custom Perm Level") # will not work, because perm levels are inherited
    $web.RoleDefinitions.BreakInheritance(true,true)
    $web.RoleDefinitions.Delete("Some Custom Perm Level") #will work