Home
Manage Your Code
Snippet: Adding a user to a Role (C#)
Title: Adding a user to a Role Language: C#
Description: Adding a user to a role is not as straight forward as it was in 2003. In 2007, you have to create a role assignment and assign the user and role to it. Views: 173
Author: Raja Ayyapusetty Date Added: 1/3/2008
Copy Code  
1SPRoleDefinition userRoleDefinition = web.RoleDefinitions["Role Definition Name"];
2SPRoleAssignment userRoleAssignment = new SPRoleAssignment(sLogin, sEmail, sName, "");
3userRoleAssignment.RoleDefinitionBindings.Add(userRoleDefinition);
4web.RoleAssignments.Add(userRoleAssignment);