Click here to Skip to main content
11,635,626 members (77,067 online)
Rate this: bad
good
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
0 OriginalGriff 8,861
1 Sergey Alexandrovich Kryukov 8,459
2 Mika Wendelius 6,849
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,270


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2015
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