Remove User From Site Group in SharePoint using CSOM

The example in this topic show how to use CSOM to Remove User From Site Group in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • // Get group object using group name
  • Group oGroup = clientcontext.Web.SiteGroups.GetByName("Group Name");
  •  
  • // Get user using Logon name
  • User oUser = clientcontext.Web.EnsureUser("Logon Name");
  •  
  • clientcontext.Load(oUser);
  • clientcontext.ExecuteQuery();
  •  
  • // Remove user from the group
  • oGroup.Users.RemoveByLoginName(oUser.LoginName);
  •  
  • clientcontext.ExecuteQuery();
  • }

Thank you for reading this article. This code was tested in SharePoint 2013

We value your feedback:

Page URL:

Name:

 

Email:

 
 

Feedback:

 

© 2019 Code SharePoint