Below is the C# function to call the UserGroup.asmx MOSS Web Service to create Uer Groups.
Add reference to UserGroup.asmx to your project and use the following code:
private void CreateUserGroup(string strGroupName, string strDescription)
{
try
{
#region Connect to UserGroup.asmx
this.objUserGroupService.Url = this.cmbURL.Text.Trim('/') + "/_vti_bin/UserGroup.asmx";
string sDomain = string.Empty;
string sUserName = this.txtLogin.Text.Trim();
if (sUserName.IndexOf("\\") > 0)
{
sDomain = sUserName.Split("\\".ToCharArray())[0];
sUserName = sUserName.Split("\\".ToCharArray())[1];
}
this.objUserGroupService.Credentials = new System.Net.NetworkCredential(sUserName, this.txtPassword.Text.Trim(), sDomain);
#endregion
this.objUserGroupService.AddGroup(strGroupName, this.txtLogin.Text.Trim(), "user", this.txtLogin.Text.Trim(), strDescription);
this.WriteLog("Created Group: " + strGroupName);
}
catch (System.Exception ex)
{
this.WriteLog(ex.ToString());
}
}
No comments:
Post a Comment