i want to implement the item leve permissions for a document library whose versioning is enabled and check-in and check-out functionality is also enabled.
i am tryng with the below
1) Everyone should get the ContributeNoDelete permission
2) Author should get the contribute permissions
3) a custom group "npd admin" should get the contribute permission
whenever i upload a document to this doc lib, its asking me to check-in the document and it remains as checked-out.
when i forcefully check-in through code, the modified by is updated as system account,!! what shoudl i do to avoid showing it as "system account" and forcefully check-in the doc.
am trying with the code below: but the issue am facing is , after forcibly check-in code am geting the modified by as system account
SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite CurrentSite = new SPSite(properties.SiteId); SPWeb CurrentWeb = CurrentSite.OpenWeb(properties.RelativeWebUrl); SPList CurrentList = CurrentWeb.Lists[properties.ListId]; SPListItem CurrentListItem; SPWeb myRootWeb = CurrentSite.RootWeb; CurrentListItem = CurrentWeb.Lists[properties.ListId].GetItemById(properties.ListItem.ID); SPFile spfile = CurrentListItem.Web.GetFile(CurrentListItem.Url); SPFolder spfileFolder = spfile.ParentFolder; if (CurrentListItem != null) { CurrentWeb.AllowUnsafeUpdates = true; if (!CurrentListItem.HasUniqueRoleAssignments) { CurrentListItem.BreakRoleInheritance(false); CurrentWeb.AllowUnsafeUpdates = true; }
SPRoleAssignmentCollectionSPRoleAssColn = CurrentListItem.RoleAssignments;
for(inti = SPRoleAssColn.Count - 1; i >= 0; i--)
{
SPRoleAssignmentroleAssignmentSingle = SPRoleAssColn[i];
System.
Typet = roleAssignmentSingle.Member.GetType();
if(t.Name == "SPGroup"|| t.Name == "SPUser")
SPRoleAssColn.Remove(i);
}
}
SPUserspevery1nodelete = CurrentWeb.EnsureUser("Everyone");
SPRoleDefinitionmroleDefinitionevery1nodelete = CurrentWeb.RoleDefinitions["ContributeNoDelete"];
SPRoleAssignmentspRoleAssignmentevery1nodelete = newSPRoleAssignment(spevery1nodelete);
spRoleAssignmentevery1nodelete.RoleDefinitionBindings.Add(mroleDefinitionevery1nodelete);
CurrentListItem.RoleAssignments.Add(spRoleAssignmentevery1nodelete);
SPUserspUsrEnsuredUser = CurrentWeb.EnsureUser(currUser.LoginName);
SPRoleAssignmentmroleAssignment = newSPRoleAssignment(spUsrEnsuredUser);
SPRoleDefinitionmroleDefinition = CurrentWeb.RoleDefinitions["Contribute"];
mroleAssignment.RoleDefinitionBindings.Add(mroleDefinition);
CurrentListItem.RoleAssignments.Add(mroleAssignment);
//this.EventFiringEnabled = false;
// if (CurrentListItem.File.CheckOutType.ToString() == "None")
{
CurrentListItem.File.CheckOut();
CurrentListItem.SystemUpdate();
//CurrentListItem.Update();