I have list of clients through which i have created SharePoint user groups with this code.
namespace CreateGroupCSharp.EventReceiver1
{
public class EventReceiver1 : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
using (SPSite site = new SPSite("http://abc/"))
{
SPWeb web = site.AllWebs[0];
SPList customList = web.Lists["Client"];
string strCount = properties.ListItem.Title.ToString();
string status = properties.Status.ToString();
SPGroup groupOwner = web.SiteGroups.GetByID(int.Parse(web.Properties["vti_associateownergroup"]));
string groupName = strCount;
web.SiteGroups.Add(groupName, groupOwner, null, "Custom SharePoint Group for Demo");
SPGroup wcmGroup = web.SiteGroups[groupName];
SPRoleDefinition designerRoleDefinition = web.RoleDefinitions["Contribute"];
SPRoleAssignment roleAssignment = new SPRoleAssignment(wcmGroup);
roleAssignment.RoleDefinitionBindings.Add(designerRoleDefinition);
web.RoleAssignments.Add(roleAssignment);
wcmGroup.Update();
web.Update();
}
base.ItemAdded(properties);
}
}
}
Is it possible to create users for each client in SharePoint list itself?
How can I assign these created groups to the the users in list?
I would add a Person or Group column named Users to your list. Allow multiple selections and allow people only (no groups) to be selected. You can then add the users to the group using the following code in your event receiver: