We have a bucketload of team sites that are created using custom code and these are constantly being created/updated/deleted.
Our security requirements mean that these sites must have unique permissions with associated owner/member/visitor groups.
When the site is deleted, however, the associated groups are left hanging around and have to be deleted manually. This doesn't happen if we create the team site through the normal sharepoint web interface.
Is there any way to make it so that our custom created groups are deleted when the site is?
We're using the following code to add the groups:
//Create the owners group
newSite.SiteGroups.Add(ownersName, owner, owner, siteName + " Owners Group");
SPGroup ownersGroup = newSite.SiteGroups[ownersName];
ownersGroup.AllowMembersEditMembership = true;
newSite.AssociatedOwnerGroup = ownersGroup;
//Add RoleAssignments and RoleDefinitions
SPRoleAssignment ownerAssignment = new SPRoleAssignment(ownersGroup);
SPRoleDefinition ownerDefinition = newSite.RoleDefinitions["Full Control"];
ownerAssignment.RoleDefinitionBindings.Add(ownerDefinition);
newSite.RoleAssignments.Add(ownerAssignment);
ownersGroup.Update();