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.
- <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
- <script type="text/ecmascript" src="../_layouts/SP.core.debug.js" />
- <script type="text/ecmascript" src="../_layouts/SP.runtime.debug.js" />
- <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.
- <script type="text/ecmascript">
- function breakPermision() {
- var Context = new SP.ClientContext.get_current();
- var Website = clientContext.get_web();
- var oList = Website.get_lists().getByTitle('CustomList');
-
- oList.breakRoleInheritance(true, false);
-
- clientContext.load(oList);
-
- clientContext.executeQueryAsync(Function.createDelegate(this, this.QuerySucceeded), Function.createDelegate(this, this.QueryFailed));
- }
-
- function QuerySucceeded(sender, args) {
-
- alert(this.oList.get_title() + ' role inheritance broken.');
- }
-
- function QueryFailed(sender, args) {
-
- alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
- }
-
- </script>
Conclusion
This article helps you to break the inheritance permission to the document library.