I have been looking around for few days, but couldn't really figure out, how I will be able to do this.

what I am doing is removing all permissions of a given list using following code,

  using (SPSite site = new SPSite("https://abc2020.development.com/portol/../default.aspx"))
                using (SPWeb web = site.OpenWeb())
                    SPList myList = web.Lists["listname"];
                    while (myList.RoleAssignments.Count > 0)

Now I want to get all the Groups/Users who have permission to web(where this list is created) and give them all my custom level permission "ABC permission level" that I created on top level sitecollection.

Oh yes there will be a user "System Account" who I wanna give FULL Control.

I looked around on google and find this code Snippet but I got no clue how can I integrate it with my situation.

    SPRoleAssignment roleAssignment = new SPRoleAssignment("dom\\user", "user@dom", "user", "some notes");
SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
if (!myList.HasUniqueRoleAssignments)
    myList.BreakRoleInheritance(true); // Ensure we don't inherit permissions from parent

Cheers Ali


I don't know how you're going to select the users but one option could be to loop through the Users collection of one/all of the web.Groups

For each User (which can be an AD-group) create a SPRoleAssignment and add web.RoleDefinitions["ABC permission level"] as RoleDefintionBinding before adding the RoleAssignment to the list.

For the "System Account" use web.RoleDefinitions.GetByType("Administrator")

  • thanks, It worked, I was wondering if you can know any good tutorial/article that will gonna help me go through concept of "Role Definition" & "RoleDefinitionBinding" & "RoleAssignment" please.. – Muhammad Raja May 31 '12 at 7:31
  • 1
    I don't have a really got reference but you should start with [msdn.microsoft.com/en-us/library/…, Groups, and Authorization) – Per Jakobsen May 31 '12 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.