Steps
- Open Visual Studio in your system
- Select console application template and give the name as anything you like.
- Add a Microsoft.Client Assembly reference file in right side reference tab in Visual Studio.
- Replace Program.cs with the source code given below.
Code snippet
- using System;
- using Microsoft.SharePoint.Client;
-
-
- namespace GowthamArticles
- {
- class Addusertogroup
- {
- static void Main()
- {
- ClientContext clientContext = new ClientContext("https://gowtham.sharepoint.com/tutorials");
- GroupCollection collGroup = clientContext.Web.SiteGroups;
- Group oGroup = collGroup.GetById(7);
-
- UserCreationInformation userCreationInfo = new UserCreationInformation();
- userCreationInfo.Email = "[email protected]";
- userCreationInfo.LoginName = @"sp\dev";
- userCreationInfo.Title = "gowtham";
- User oUser = oGroup.Users.Add(userCreationInfo);
- clientContext.ExecuteQuery();
-
-
- }
- }
- }
Thanks for reading my blog.