0

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"];
                    myList.BreakRoleInheritance(true);
                    while (myList.RoleAssignments.Count > 0)
                        myList.RoleAssignments.Remove(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);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
if (!myList.HasUniqueRoleAssignments)
{
    myList.BreakRoleInheritance(true); // Ensure we don't inherit permissions from parent
} 
myList.RoleAssignments.Add(roleAssignment);
myList.Update();

Cheers Ali

1 Answer 1

0

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

2
  • 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.. May 31, 2012 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) May 31, 2012 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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