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