SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(""))
                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

share|improve this question
up vote 0 down vote accepted

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")

share|improve this answer
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
I don't have a really got reference but you should start with […, Groups, and Authorization) – Per Jakobsen May 31 '12 at 10:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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