I've seen many ways to remove groups from a document library in SharePoint 2013. But what I need to do is to remove an individual's permissions to a document library and not a group.
This is the code I've been using. It runs without error, but it fails to remove the users permission on the document library.
I do not want to remove the user from any groups or from the site.
public void DeleteUserFromDocumentLibrary(string fullUserLogon, string shareName)
{
string Myurl = "https://host.domainname.com/fs";
using (SPSite site = new SPSite(Myurl))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
web.ValidateFormDigest();
fullUserLogon = "i:0#.w|" + fullUserLogon;
SPPrincipal principal = web.EnsureUser(fullUserLogon);
SPRoleAssignment rAssignment = new SPRoleAssignment(principal);
SPList list = web.Lists[shareName];
foreach (SPListItem item in list.Items)
{
item.BreakRoleInheritance(true);
item.RoleAssignments.Remove(principal);
item.Update();
}
web.AllowUnsafeUpdates = false;
}
site.AllowUnsafeUpdates = false;
}
}
Thanks