Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to Add a User to the Site Group Programmatically
WhatsApp
Gowtham Rajamanickam
9y
26.1
k
0
1
25
Blog
Steps
Open Visual Studio in your system.
Select Console Applciation template and give as name .
Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
Replace Program.cs with the source code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.IO;
namespace CSOMCodeSamples
{
class
Program
{
static
void
Main(string[] args)
{
// ClientContext - Get the context for the SharePoint Site
ClientContext clientContext =
new
ClientContext(
"http://servername/sites/CSOM/"
);
// Get the SharePoint web
Web web = clientContext.Web;
User user = web.EnsureUser(
"Gowtham"
);
// Get the specific site group by name
Group group = web.SiteGroups.GetByName(
"CSOM Owners"
);
// Add a user to the specific group
group.Users.AddUser(user);
// Execute the query to the server
clientContext.ExecuteQuery();
}
}
}
Hit F5 and check the output.
Add a user to the site group Programmatically
Add user in SharePoint
Up Next
Programmatically Check whether Current Logged in User is a Member of SharePoint User Group or Not
Ebook Download
View all
Getting Started with SharePoint Framework Development using TypeScript, PnP JS, and React JS
Read by 4.9k people
Download Now!
Learn
View all
Membership not found