Stop Inheritance Permission In SharePoint Document Library

Introduction

In this article we will learn about how to break document Library permissions inheritance using OOTB method.

In Microsoft SharePoint all sites, lists, and libraries in a site collection inherit permissions settings from the site that is directly from the root site.The items,pages, and files you store on a SharePoint site, list, and library are easily accessible to everyone with permissions to the site.

Sometimes,you may want to share specific files or folders with people who don't have permission to access the site.

Simply put, the SharePoint site inherits permissions from the root site of the site collection, and a sub site inherits permissions from its parent site.

  • Go to the library or list and open it.
  • Choose Settings  and then Library settings.


On the Settings page, under Permissions and Management, click Permissions for this list or Permissions for this document library.


To break inheritance and assign unique permissions, follow these steps,


You will get alert message before breaking the permission. When permission inheritance is broken, all permissions are explicit and any changes to parent object do not affect the child object.


Items under that parent now inherit the new permission settings (unless the items have uniquely defined permissions.When you share files and folders, you can decide whether to let people edit or just view them.

After you stop the inherit permission we can add a new permission to the files like below,


Now new permission is added to the library.

Programmatically Stop Inherit Permission using JSOM

 You can break the security inheritance of a website, list, or list item through the BreakRoleInheritance method of the object so that role assignments on the parent object no longer apply to the child object,

Sample Code

Add below JavaScript files in to your solution. 

  1. <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>  
  2. <script type="text/ecmascript" src="../_layouts/SP.core.debug.js" />  
  3. <script type="text/ecmascript" src="../_layouts/SP.runtime.debug.js" />  
  4. <script type="text/ecmascript" src="../_layouts/SP.debug.js" />  

The following blog shows how to break the security of a list by using the breakRoleInheritance(copyRoleAssignments, clearSubscopes) function of the List object. 

  1. <script type="text/ecmascript">  
  2.     function breakPermision() {  
  3.         var Context = new SP.ClientContext.get_current();  
  4.         var Website = clientContext.get_web();  
  5.         var oList = Website.get_lists().getByTitle('CustomList');  
  6.   
  7.     oList.breakRoleInheritance(truefalse);  
  8.   
  9.     clientContext.load(oList);  
  10.   
  11.     clientContext.executeQueryAsync(Function.createDelegate(thisthis.QuerySucceeded), Function.createDelegate(thisthis.QueryFailed));  
  12. }  
  13.   
  14. function QuerySucceeded(sender, args) {  
  15.   
  16.         alert(this.oList.get_title() + ' role inheritance broken.');  
  17. }  
  18.   
  19. function QueryFailed(sender, args) {  
  20.   
  21.         alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());  
  22. }  
  23.   
  24. </script>   

Conclusion

This article helps you to break the inheritance permission to the document library.