Click here to Skip to main content
12,942,930 members (60,041 online)
Rate this:
Please Sign up or sign in to vote.
See more:

how to add the group and user in sharepoint in Programmatically

thank you.
Posted 22-Apr-12 21:26pm
Rate this: bad
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);
           // 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;

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Select ListSeettings>Permissions>AddUserOrGroup To List

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
OriginalGriff 4,633
CHill60 2,880
Maciej Los 2,268
Jochen Arndt 1,900
ppolymorphe 1,755

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