Tuesday, 2 September 2008

Adding Groups and Users to a SharePoint Site in code

There are plenty of blogs around about adding users to groups, but i have found there are not many explaining the end to end code for the creation of a new group in a site, assigning the permissions then adding of users to that group, so here goes.

Firstly, when you add a group to a site, it is not just the simple case of using the SPGroupCollection add method of the SPWeb object,  you need to follow this up by setting the RoleAssignments and RoleDefinitionsBindings.