Click here to Skip to main content
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 CHill60 525
1 Sergey Alexandrovich Kryukov 469
2 OriginalGriff 325
3 PIEBALDconsult 285
4 BillWoodruff 193


Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
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