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.


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("Name: "+role.Member.Name);

                            SPRoleDefinitionBindingCollection bindings = role.RoleDefinitionBindings;

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

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

|improve this answer|||||
  • As i am working on a folder in document library, so how to get the folder using list? – Md. Tahmidul Abedin Apr 4 '16 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 – Ankitkumar Malde Apr 4 '16 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. – Md. Tahmidul Abedin Apr 5 '16 at 11:35

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.