If you created a custom site definition or site template and everything works fine, one of the last steps is thinking of the security groups or the SharePoint groups which are created by default.
Those are visitors, owner and members. The name is normally “owner of + web title”. But what if you would like to rename it or just give this user group a different role definition?
Well, i first thought, no problem, delete them and create your own permission level and groups in an event receiver – like in this post. But i was wrong, i tried it with an event receiver, with a custom SPWebProvisioningProvider – but nothing helped. The default groups are always created after i the web is provisioned.
The Trick
I wouldn’t write about it, if there is no solution. So finally i got a clue from sharepointcommunity.de which helped me. In the event receiver you simply call the function to create the default groups and the rename each one and also assign another role definition. So SharePoint needs the default groups, but it provides to change them.
So let me show you how to do:
[sourcecode language=”csharp”]
//first create default groups
rootWeb.CreateDefaultAssociatedGroups(rootWeb.Site.Owner.LoginName, rootWeb.Site.Owner.LoginName, rootWeb.Title);
//Get the Member Group
SPGroup dMember = rootWeb.Groups[rootWeb.AssociatedMemberGroup.Name];
//Change name
dMemberDel.Name = web.Title + ” Member with Delete Rights”;
//Get Role assignment
SPRoleAssignment roleAssignMember = web.RoleAssignments.GetAssignmentByPrincipal(dMember);
//Remove Binding if you like
roleAssignMemberNoDel.RoleDefinitionBindings.RemoveAll();
//Add your own binding
roleAssignMemberNoDel.RoleDefinitionBindings.Add(roleDefContribute);
//Update Roleassignment
roleAssignMemberNoDel.Update();
//Group Update
dMemberDel.Update();
[/sourcecode]
After the site is created, it works really fine. If you saw the web.associatedgroups property – that’s the quicklaunch of the group settings page. You can add your custom group to it. Really cool.
..:: I LIKE SHAREPOINT ::..
Can we change Member permission from edit to contribute using this