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 clientContext = new ClientContext("http://servername/sites/CSOM/");
-
- Web web = clientContext.Web;
- User user = web.EnsureUser("Gowtham");
-
- Group group = web.SiteGroups.GetByName("CSOM Owners");
-
- group.Users.AddUser(user);
-
- clientContext.ExecuteQuery();
- }
- }
- }
Hit F5 and check the output.