0

I have document library & 3 groups(AdminGroup,Reviewer,Distributor). I have already give a permission on groups, AdminGroup has Full Control, Reviewer has Reader & Distributor has None :


 roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Administrator); // Admin
 roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Reader); // Reviewer
 roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.None); // Distributor

Now, I want to give permission on document library that :

  • If anyone upload document it's Draft version should only visible to Reviewer,Admin & owner of the document. Distributor user can't see it if he is not owner.
  • Reviewer Group's user can only view/edit the document & publish it but can't Approve/Reject it.
  • Admin has full control. He can Add/Edit/View & Approve/reject the document.
  • Distributor Group's user can only view his own documents & Approved documents.
0

Attach a event recevier and add item added / updated event to it for assigneing permission.

First break permission on item and then add required permission as per item status / metadata.

0

I have found the solution to assign permission to group:

 using (SPSite spSite = SPContext.Current.Site)
  {
     using (SPWeb web = spSite.OpenWeb())
     {
        web.AllowUnsafeUpdates = true;
        SPGroupCollection grpColl = SPContext.Current.Site.OpenWeb().SiteGroups;
        SPGroup spGroup =  grpColl.GetByName("myGroup");

SPRoleAssignment roleAssignment = new SPRoleAssignment(spGroup); SPRoleDefinition roleDefinition = new SPRoleDefinition(); roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Administrator); // for admin role SPRoleDefinitionBindingCollection roleDefinitionBindingCollection = new SPRoleDefinitionBindingCollection(); roleDefinitionBindingCollection.Add(roleDefinition); roleAssignment.ImportRoleDefinitionBindings(roleDefinitionBindingCollection); web.AllowUnsafeUpdates = true; web.RoleAssignments.Add(roleAssignment); web.update(); web.AllowUnsafeUpdates = false; }}

Then, Give same permission to Document Library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.