public void AddUserToSPGroup(String userName,string group)
{
try
{
SPWeb web = site.AllWebs[ConfigurationManager.AppSettings["WEB_SITE"].ToString()];
//SPUser spUser = web.AllUsers[domain + "\\" + userName];
SPUser spUser = web.AllUsers["ad:"+ userName];
//Open group
SPGroup spGroup = web.SiteGroups[group];
//Add and update group with new user
web.AllowUnsafeUpdates = true;
spGroup.AddUser(spUser.LoginName, spUser.Email, spUser.Name, "Added by UserControl");
spGroup.Update();
}
catch(Exception ex)
{
//Response.Write(ex.Message);
lblUserList.Text =ex.Message.ToString();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment