SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb currentWeb = SPControl.GetContextWeb(Context);
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPUser user =
web.EnsureUser(peCheckUser.Accounts[0].ToString());
SPGroupCollection collGroups = user.Groups;
if (collGroups.Count > 0)
{
foreach (SPGroup oGroup in collGroups)
{
oGroup.RemoveUser(user);
}
strError += "User Removed Successfully...!";
}
else
{
strError += "User not found in any of the
groups...!";
}
}
}
});
{
SPWeb currentWeb = SPControl.GetContextWeb(Context);
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPUser user =
web.EnsureUser(peCheckUser.Accounts[0].ToString());
SPGroupCollection collGroups = user.Groups;
if (collGroups.Count > 0)
{
foreach (SPGroup oGroup in collGroups)
{
oGroup.RemoveUser(user);
}
strError += "User Removed Successfully...!";
}
else
{
strError += "User not found in any of the
groups...!";
}
}
}
});
No comments:
Post a Comment