Creating SharePoint Group Using SharePoint Designer 2013

I am trying to automate the process of creating private team sites in my SharePoint environment. I have successfully achieved creating the actual team site and have my users filling out a form with basic info (Site name, URL, description, etc.) However, I do not want the site to inherit the permissions of the parent site. I would like to create new groups for these sites automatically based on addition questions I will add to my form and have users add to these group automatically. Any ideas on how to achieve this?

May 18th, 2015 3:56pm

Hi Smith,

You can achieve this through implementing event receiver code developed using visual studio. When users would fill out a form and save it to the library, write an event receiver on ItemAdded event that would retrieve the values filled in the control fields of the form.

spWeb.SiteGroups.Add(groupName, spWeb.SiteAdministrators[0], null, "New group created");
SPGroup secGroup = spWeb.SiteGroups[groupName];
spWeb.AssociatedGroups.Add(secGroup);
SPRoleAssignment roleAssignment = new SPRoleAssignment(secGroup);
SPRoleDefinition roleDefinition = spWeb.RoleDefinitions["Contribute"];
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
spWeb.BreakRoleInheritance(false);

spWeb.RoleAssignments.Add(roleAssignment);
secGroup.Update();
spWeb.Update();

Like in the above code you can retrieve groupName as a variable from form textbox field and feed it to SPGroup class.

You can break the security inheritance of a Website, list, or list item through the BreakRoleInheritance method of the object so that role assignments on the parent object no longer apply to the child object.

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 2:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics