Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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

 
discard

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.