4

I am working with SharePoint 2010 . I have a folder in my SharePoint document library. I am trying to get the users who have any permission or role to that folder programmatically. But can't find a way to get the list of these users.

Thanks in advance.

2

1 Answer 1

2

Can you try this code snippet

public static void getPermissionsOfFolders()
    {
        using (SPSite site = new SPSite("http://sp"))
        {
            using (SPWeb web = site.RootWeb)
            {
                SPList list = web.GetList("/Lists/List2");
                foreach (SPListItem item in list.Folders)
                {
                    Console.WriteLine("ID: "+item["ID"]+"--"+item.SortType);
                    if (SPFileSystemObjectType.Folder == item.SortType)
                    {
                        SPRoleAssignmentCollection roles = item.RoleAssignments;
                        foreach (SPRoleAssignment role in roles)
                        {
                            Console.WriteLine("~");
                            Console.WriteLine("Name: "+role.Member.Name);

                            SPRoleDefinitionBindingCollection bindings = role.RoleDefinitionBindings;

                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(bindings.Xml);
                            XmlNodeList itemList = doc.DocumentElement.SelectNodes("Role");
                            foreach (XmlNode currNode in itemList)
                            {
                                string s = currNode.Attributes["Name"].Value.ToString();
                                Console.WriteLine("Permission Level: "+s);
                            }
                        }
                        Console.WriteLine("--------------------------------------");
                    }  
                }                                  
            }
        }
    }

Found same from the link: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8c7c5735-039e-4cb9-a2b5-58d70a10793f/get-permissions-group-from-folders-tree-view-on-a-doc-library?forum=sharepointdevelopmentprevious

Also you can refer to this link for CSOM approach https://stackoverflow.com/questions/32163483/code-to-list-all-permissions-for-sharepoint-folders

3
  • As i am working on a folder in document library, so how to get the folder using list? Apr 4, 2016 at 8:42
  • U would just give it a try... As folder is also one item and you can check in the code snippet that we are working with folders in the library Apr 4, 2016 at 9:11
  • Its giving FileNotFoundException as there is no list named "List2" is not existed in my list. I didn't find any way to get the list which contains the document library folders using web-part. Apr 5, 2016 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.