In this post we will discuss how we can add security to group to SharePoint using SharePoint 2010 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 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 AddGroup method takes 5 parameters like below:
public void AddGroup(string groupName, string ownerIdentifier, string ownerType, string defaultUserLoginName, string description)
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.AddGroup("TestGroup", "ASIAPACIFIC\\SAHOOBIJ", "user", "ASIAPACIFIC\\SAHOOBIJ", "Test group created from code.");
catch (Exception ex)
Once you will execute the code, the group will appear like below: