문제

다음 코드를 사용하여 설정된 문서 내의 서브 폴더에서 상속을 끊으려고합니다.코드를 실행하고 문서 세트의 하위 폴더를 검사 한 후에는 아직도 상위에서 상속받을 수 있습니다.아무도 여기서 틀린 것을 볼 수 있습니까?

using(var site = new SPSite("http://tmtech-sp13b:8080/sites/Doc%20Set%20Test")) {
 // TODO: Replace with current site
 using(var web = site.AllWebs[0]) {
  SPList list = web.Lists["Projects"];

  // Test if list has project document set content type
  if (list.ContentTypes.Cast < SPContentType > ().Any(c => c.Parent.Id == _projContentTypeId)) {

   foreach(SPFolder projfolder in list.RootFolder.SubFolders) {
    if (projfolder.Name.ToLower() != "forms") {
     Console.WriteLine(projfolder.Name);

     // Container to hold the temporary files which are to be deleted.
     List < SPFile > files2Delete = new List < SPFile > ();

     foreach(SPFolder projSubFolder in projfolder.SubFolders) {
      // Set Contractor Permissions
      if (projSubFolder.Name == CONTRACTOR_FOLDER_NAME) {

       SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal) web.SiteGroups["Contractors"]);

       SPFolder f = web.GetFolder(projSubFolder.Item.Url);
       SPListItem i = f.Item;
       i.BreakRoleInheritance(true);

       roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions["Contribute"]);
       i.RoleAssignments.Add(roleAssignment);

       web.AllowUnsafeUpdates = true;
       i.Update();
       web.Update();
       web.AllowUnsafeUpdates = false;
      }

      // Capture the temporary files
      foreach(SPFile file in projSubFolder.Files) {
       if (file.Name.ToLower().Contains("temporary document delete me")) {
        files2Delete.Add(file);
       }
      }
     }

     // Delete Temporary Files
     foreach(SPFile f in files2Delete) {
      f.Delete();
      f.ParentFolder.Update();
     }
    }
   }
  }
 }
}
.

도움이 되었습니까?

해결책

You'll want to use i.BreakRoleInheritance(false) on this one, instead of true.

From this: https://social.technet.microsoft.com/forums/sharepoint/en-US/313effab-a5af-4fda-b39c-37f620fe95f2/itembreakroleinheritancetrue-vs-itembreakroleinheritancefalse

"

When you call SPItem.BreakRoleInheritance(true), you are assigning the list item with unique permissions, while copying existing permissions on the list to the item. Any new permissions added to the item are only applied to the item.

When you call SPItem.BreakRoleInheritance(false), you are assigning the list item with unique permissions. Existing permissions on the list are NOT copied to the list item. Any new permissions added to the item are only applied to the item.

"

다른 팁

Your code should work from what I can see, haven't tested it. But you use i.BreakRoleInheritance(true); , meaning it will copy all the permissions it has before breaking the inheritance (from the parent). Are you sure it does not say "This folder has unique permissions." when you check the permission of the SubFolders in the GUI?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top