When you perform the site backup if you remove the users from the group but still the user details are available in the user information list
Delete the Staging server Users from the User Information List
public void DeleteStagingUsers(string siteurl, string UserName)
{
try
{
using (SPSite osite = new SPSite(siteurl))
{
foreach(SPWeb oweb in osite.AllWebs)
{
SPList oinfolist = oweb.Lists["User Information List"];
oweb.SiteUserInfoList.AllowDeletion = true;
SPListItemCollection oitemcol = oinfolist.Items;
foreach (SPListItem oitm in oitemcol)
{
string strName = Convert.ToString(oitm["Name"]);
if (strName.ToLower().Contains(UserName.ToLower() ))
{
oweb.AllowUnsafeUpdates = true;
int ItemId = Convert.ToInt32(oitm["ID"]);
oweb.SiteUsers.RemoveByID(ItemId);
oweb.AllowUnsafeUpdates = false;
}
}
}
}
}
}
Delete the Staging server Users from the User Information List
public void DeleteStagingUsers(string siteurl, string UserName)
{
try
{
using (SPSite osite = new SPSite(siteurl))
{
foreach(SPWeb oweb in osite.AllWebs)
{
SPList oinfolist = oweb.Lists["User Information List"];
oweb.SiteUserInfoList.AllowDeletion = true;
SPListItemCollection oitemcol = oinfolist.Items;
foreach (SPListItem oitm in oitemcol)
{
string strName = Convert.ToString(oitm["Name"]);
if (strName.ToLower().Contains(UserName.ToLower() ))
{
oweb.AllowUnsafeUpdates = true;
int ItemId = Convert.ToInt32(oitm["ID"]);
oweb.SiteUsers.RemoveByID(ItemId);
oweb.AllowUnsafeUpdates = false;
}
}
}
}
}
}
Comments
Post a Comment