locked
How to programmatically create a group? RRS feed

  • Question

  •  How do I programmatically create a user group via the Sharepoint API?

    I can't seem to find it in the Sharepoint API docs....

    There's a method GetGroupsforUser() in SharePointUserService class ...I want a method that will create one of those groups

    Which class can I find this under and what's the appropriate method?

    Thanks,
    Phil

    Friday, August 1, 2008 5:01 PM

Answers

  • You can programmatically create groups . There is a property called SiteGroups inside SPWeb class.
    You can use this SiteGroups property to add the group programmatically.

    The following snippet should do the trick

    //Add the group to the SPWeb web
    web.SiteGroups.Add(groupName, owner, defaultuser, description);

    //Associate de group to the SPWeb. Now it will display in the quick launch bar
    web.AssociatedGroups.Add(web.SiteGroups[groupName);
    web.Update();

    Saturday, August 2, 2008 4:16 PM