SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPControl.GetContextWeb(Context);
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb objWeb = site.OpenWeb())
{
objWeb.AllowUnsafeUpdates = true;
SPUser spUser = objWeb.EnsureUser(peAddUser.Accounts[0].ToString());
if (spUser != null)
{
SPGroup spGroup = objWeb.Groups["Name of Your Group"];
if (spGroup != null)
{
spGroup.AddUser(spUser);
string strUrl=objWeb.Url+"/UserPages/Add User.aspx";
Page.Response.Redirect(strUrl);
}
}
}
}
});
No comments:
Post a Comment