In this post we will discuss about how to add user to SharePoint group using SharePoint web service. Also you can check out my previous posts on:
To work with SharePoint web service we need to give the web service reference into SharePoint solution. To add a user to a security group we need to give reference to the UserGroup.asmx web service.
Here we give the reference like below:
Once we give reference we can use the AddGroup method to add a group to SharePoint.
Here the AddUserToGroup method takes 5 parameters like below:
public void AddUserToGroup(string groupName, string userName, string userLoginName, string userEmail, string userNotes)
Below is the full code:
UserGroup userGroup = new UserGroup();
userGroup.Url = "http://bsahoo3:18649/_vti_bin/UserGroup.asmx";
userGroup.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
userGroup.AddUserToGroup("Viewers", "Sahoo, Bijaya Kumar", "ASIAPACIFIC\\SAHOOBIJ", "firstname.lastname@example.org", "User Added");
catch (Exception ex)
Once you will execute the code, the group will appear like below: