Home > SharePoint Development > How to add user in group in Sharepint site using C#

How to add user in group in Sharepint site using C#

This code will help to understand, how to add user to group or site with permission.

SPGroup group = web.Groups["Site Member"];
//Add a new user to the group

group.AddUser("DOMAIN\\SandyUser","Sandy@sandy.com","Sandy user","Notes");

//Update the group

group.Update();

//Update the SPWeb

web.Update();

————————–Another way———————————————

SPWeb
mySite = SPControl.GetContextWeb(Context);

SPRole
admins = mySite.Roles["Administrator"]

admins.AddUser("DOMAIN\\SandyUser","Sandy@sandy.com","Sandy
user","Notes");

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: