1

I have a document library and it has nested folder structure. Each Folder has Unique permission and some SP groups have been to them. How can I get the list of the SP groups having permission on the particular folder using client scripts only (SPSeriveces/REST API/JSOM)?

Thanks.

  • by client script do you mean browser based scripting or you can go with C# client side object model as well? – ThinkB4Code Jun 23 '17 at 11:55
  • only browser based scripting. – SPContext Jun 24 '17 at 7:04
  • Hi, i added the JSOM port of same code written in CSOM. Kindly check that. Inside currentFolder, you'll get all the roles. You need to extract from that. – ThinkB4Code Jun 24 '17 at 13:18
1

That's a rat's nest.

I don't think that this can be done with SPServices, REST or JSOM, especially least not in 2010, where there is no JSOM.

You will need Powershell for that.

| improve this answer | |
1

If you prefer CSOM as a solution you can use following script to read the folder permissions:

ClientContext ctx = new ClientContext("http://server:port/sites/test");
Web web = ctx.Web;
List test = web.Lists.GetByTitle("Test Docs");
ListItemCollection itemColl = test.GetItems(CamlQuery.CreateAllFoldersQuery());
ctx.Load(itemColl, x => x.Include(y => y.RoleAssignments.Include( z=> z.Member), y => y.DisplayName));
ctx.ExecuteQuery();

foreach (ListItem item in itemColl)
{
    Console.Write(item.DisplayName + " folder permissions are: ");
    foreach (RoleAssignment role in item.RoleAssignments)
    {
        Console.Write(role.Member.Title + "\t");
    }
    Console.WriteLine("\n\n");
}

Edit
JSOM port of above code.

ExecuteOrDelayUntilScriptLoaded(GetFolderGroupPermissions, 'sp.js');
var allFolders;
function GetFolderGroupPermissions(){
    debugger;
    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle('Test Docs');
    var folderQuery = SP.CamlQuery.createAllFoldersQuery();
    allFolders = list.getItems(folderQuery);
    ctx.load(allFolders, 'Include(DisplayName, RoleAssignments, RoleAssignments.Include(Member))');
    ctx.executeQueryAsync(function(){
        var allFolderEnum = allFolders.getEnumerator();
        while(allFolderEnum.moveNext()){
            var currFolder = allFolderEnum.get_current();
            var roles = currFolder.get_roleAssignments();
            var allRoles = roles.getEnumerator();
            console.log(currFolder.get_displayName());
            while(allRoles.moveNext()){
                var currentRole = allRoles.get_current();
                console.log(currentRole.get_member().get_loginName());
            }

        }
    }, function(){})
    console.log(ctx);
}

Kindly note, the first console log will provide you the Folder Name, while the second console log will give you folder/user permission.

| improve this answer | |
  • You can execute this script outside of SP farm as its Client Side Solution, just refer to SP client and runtime dll. – ThinkB4Code Jun 23 '17 at 12:48

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.