I want set permission file or folder to nobody can access it. how to deny all users or groups to access any file and folder of document library in share point 2010 ?
2 Answers
In case you do not have access to run powershell or a console application and the items with broken inheritance are limited, you can try the following:
- Navigate to the library and select "Library Permissions"
- Click "Show me uniqely secured items of this list"
- Click "Manage permissions" for each item and click the "Inherit Permissions" button on the Ribbon.
This way, all the items will eventually inherit permissions from the library, which has no assigned permissions for any user (apart from the site collection admin).
Of course it will only work for a limited amount of items with unique permissions. If you have houndreds or thousands of broken permissions (which you should not as it is a bad practice) you will have to use a script.
The same in PowerShell:
$webUrl = "http://mySite"
$web = Get-SPWeb $webUrl
$list = $web.Lists["myLibrary"]
#Using foreach is time consuming
foreach ($item in $list.items) {
$item.ResetRoleInheritance()
}
And some C# sample:
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://localhost/sites/sitecollection")
{
using (SPWeb web = site.OpenWeb("sitecollection/subsite"))
{
SPList list = web.Lists["someList"];
foreach (SPListItem folder in list.Folders)
{
if (folder.HasUniqueRoleAssignments)
{
folder.ResetRoleInheritance();
}
}
foreach (SPListItem item in list.Items)
{
if (item.HasUniqueRoleAssignments)
{
item.ResetRoleInheritance();
}
}
}
}
}
}
}
-
provide code in asp.net c# .i want for client object model Commented May 19, 2014 at 14:29
-
Powershell is the preferred way for this kind of administrative tasks– yandrCommented May 19, 2014 at 22:08
Go to library permissions -> Stop inheriting permissions -> then select all users and then click remove users permissions.
-
i have done it but when i select any file and select manage permission and then check permission for any user it showing allow for all permission Commented May 19, 2014 at 12:21
-
But any user would not be able to navigate to that document library except site collection admin and system account.– AanchalCommented May 19, 2014 at 12:29
-
those file also i am able to see from different account which has no permission to access it Commented May 19, 2014 at 12:35
-
Then you have to remove the permissions programatically from files.c-sharpcorner.com/uploadfile/Ravish001/…– AanchalCommented May 19, 2014 at 12:39