While developing user registration in an sharepoint form authentication site we need to test the user registration process so i have create a small code to delete the user from sharepoint site, member ship provider and sharepoint site if already added.
Microsoft.Office.Server.ServerContext context = Microsoft.Office.Server.ServerContext.GetContext(new SPSite("http://mysite:8888"));
Microsoft.Office.Server.UserProfiles.UserProfileManager profileManager = new Microsoft.Office.Server.UserProfiles.UserProfileManager(context);
try
{
objWeb.SiteUsers.Remove(sLoginName);
objWeb.Update();
}
catch { }
try
{
profileManager.RemoveUserProfile(sLoginName);
}
catch { }
try
{
Membership.DeleteUser(sLoginName);
}
catch { }
Add a connection string for your membership provider in app.config in case of windows application
Add the reference to microsoft.sharepoint.dll and Microsoft office server dll.
Microsoft.Office.Server.ServerContext context = Microsoft.Office.Server.ServerContext.GetContext(new SPSite("http://mysite:8888"));
Microsoft.Office.Server.UserProfiles.UserProfileManager profileManager = new Microsoft.Office.Server.UserProfiles.UserProfileManager(context);
try
{
objWeb.SiteUsers.Remove(sLoginName);
objWeb.Update();
}
catch { }
try
{
profileManager.RemoveUserProfile(sLoginName);
}
catch { }
try
{
Membership.DeleteUser(sLoginName);
}
catch { }
Add a connection string for your membership provider in app.config in case of windows application
Add the reference to microsoft.sharepoint.dll and Microsoft office server dll.
No comments:
Post a Comment