using Microsoft.SharePoint;
public void AddUserToSPGroup(String _UserName, string _GroupName)
{
try
{
SPSite site = new SPSite(ConfigurationManager.AppSettings["SITE_URL"].ToString());
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[_GroupName];
//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)
{
lblUserList.Text = ex.Message.ToString();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment