Click here to Skip to main content
12,356,331 members (64,453 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SharePoint
hello,

how to add the group and user in sharepoint in Programmatically

thank you.
Posted 22-Apr-12 21:26pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

private void AddGroupAndUsers()
        { 
            SPWeb web = SPContext.Current.Web;
            web.AllowUnsafeUpdates = true;
            web.SiteGroups.Add("MyTestGroup", web.CurrentUser, web.CurrentUser, string.Empty);
 
            //Then you probably want to give some permissions to group (let’s try to provide contributor role)

            SPGroup group = web.SiteGroups["MyTestGroup"];
            SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Contributor);
            SPRoleAssignment roleAssigment = new SPRoleAssignment(group);
            roleAssigment.RoleDefinitionBindings.Add(roleDefinition);
            web.RoleAssignments.Add(roleAssigment);
            web.Update();
 
           // Now you can add some users to your new group:

            SPUser spUser = web.EnsureUser("server\\username");
            group.Users.Add(spUser.LoginName, spUser.Email, spUser.Name, spUser.Notes);
            web.AllowUnsafeUpdates = false;
}
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Select ListSeettings>Permissions>AddUserOrGroup To List
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100