How to add a specific SharePoint group to the list

using (SPSite site = (SPSite)properties.Feature.Parent) { using (SPWeb web = site.OpenWeb()) { if (web != null) { web.AllowUnsafeUpdates = true; SPList list = web.Lists["Alert Status v1.0"]; //Creates a new role assignment for a group SPGroup myGroup = web.SiteGroups["IKM Manager"]; SPRoleAssignmentCollection roleAssignments = web.RoleAssignments; // SPRoleAssignment accepts a SPPrincipal which can be a SPUser or SPGroup SPRoleAssignment roleAssignment = new SPRoleAssignment(myGroup); //Add the new role assignment to the collection of role assignments for the site. roleAssignments.Add(roleAssignment); // Stop inheriting permissions list.BreakRoleInheritance(true); list.RoleAssignments.Add(roleAssignment); list.Update(); 

I have a bug in RoleAssignments.Add (roleAssignment) as "Cannot add role assignment with empty role definition binding assembly". I want to stop inheriting permissions and add a specific group to the permissions list. Could you help me? you are welcome..

thanks

+4
source share
2 answers

That should work.

 list.BreakRoleInheritance(true); SPGroup groupAdmin = web.SiteGroups["IKM Manager"]; SPRoleAssignment roleAssignmentAdmin = new SPRoleAssignment((SPPrincipal)groupAdmin); SPRoleDefinition roleAdmin = web.RoleDefinitions.GetByType(SPRoleType.Administrator); roleAssignmentAdmin.RoleDefinitionBindings.Add(roleAdmin); list.RoleAssignments.Add(roleAssignmentAdmin); list.Update(); 
+15
source

You need to add a role definition binding to the role assignment, for example, add a contributor role definition

 roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Contributor)); 
+4
source

All Articles