用于列出SharePoint文件夹

时间:2015-08-23 05:26:35

标签: c# sharepoint

我正在使用一些C#代码来递归枚举SharePoint网站中的所有文件夹,并列出适用于从Sharepoint客户端计算机运行的权限。任何人都可以提供或指出一个例子吗?

以下代码可以使用SPSite对象(来自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)在服务器上执行此功能,但我需要使用SharePoint客户端代码运行它

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("--------------------------------------");
                        }  
                    }                                  
                }
            }
        }

下面的代码失败,异常“未找到Property ListItemAllFields”,如下clientContext.ExecuteQuery()

所示
   private void ListSPPermissions3()
    {
            string sSite = "http://server2012a/sites/TestDocs/";
            using (var clientContext = new ClientContext(sSite))
            {
                Site site = clientContext.Site;
                Web web = clientContext.Web;
                List list = web.Lists.GetByTitle("Shared Documents");

                clientContext.Load(list.RootFolder.Folders); //load the client object list.RootFolder.Folders
                clientContext.ExecuteQuery();
                int FolderCount = list.RootFolder.Folders.Count;

                foreach  (Microsoft.SharePoint.Client.Folder folder in list.RootFolder.Folders)
                {

                        RoleAssignmentCollection roleAssCol = folder.ListItemAllFields.RoleAssignments;

                        clientContext.Load(roleAssCol); 
                        clientContext.ExecuteQuery(); // Exception property ListItemAllFields not found

                        foreach (RoleAssignment roleAss in roleAssCol)
                        {
                            Console.WriteLine(roleAss.Member.Title);
                        }
                }
            }
    }

0 个答案:

没有答案