0

我有一个文档库。在文档库中,我有一个名为 Studies 的文件夹。在研究中,我有 10 个文件夹和后续的子文件夹。

我需要使用客户端对象模型 SharePoint 2010 在树视图中填充相同内容。

DocLibrary1>>Studies>>Study1- Folder1
                             -Folder2
                             -Folder3

我想在一个函数中的树视图中发布它,我可以在其中传递文档库并返回树视图。

4

1 回答 1

0

The Following code will Display all Libraries and Folders of each Library

private void frmForm1_Load(object sender, EventArgs e)
{
    using (ClientContext clientcontext= new ClientContext("http://your server"))
    {

        //Load Libraries from SharePoint
        clientcontext.Load(clientcontext.Web.Lists);
        clientcontext.ExecuteQuery();
        foreach (List list in clientcontext.Web.Lists)
        {
           try
           {
                if (list.BaseType.ToString() == "DocumentLibrary" && !list.IsApplicationList && !list.Hidden && list.Title != "Form Templates" && list.Title != "Customized Reports" && list.Title != "Site Collection Documents" && list.Title != "Site Collection Images" && list.Title != "Images")
                {
                    clientcontext.Load(list);
                    clientcontext.ExecuteQuery();
                    clientcontext.Load(list.RootFolder);
                    clientcontext.Load(list.RootFolder.Folders);
                    clientcontext.ExecuteQuery();
                    TreeViewLibraries.ShowLines = true;
                    TreeNode LibraryNode = new TreeNode(list.Title);
                    TreeViewLibraries.Nodes.Add(LibraryNode);
                        foreach (Folder SubFolder in list.RootFolder.Folders)
                        {
                            if (SubFolder.Name != "Forms")
                            {
                                TreeNode MainNode = new TreeNode(SubFolder.Name);
                                LibraryNode.Nodes.Add(MainNode);
                                FillTreeViewNodes(SubFolder, MainNode, clientcontext);
                            }
                        }

                }
            }

        }
    }
}


//Recursive Function

public void FillTreeViewNodes(Folder SubFolder, TreeNode MainNode, ClientContext clientcontext)
{
    clientcontext.Load(SubFolder.Folders);
    clientcontext.ExecuteQuery();
        foreach (Folder Fol in SubFolder.Folders)
        {
            TreeNode SubNode = new TreeNode(Fol.Name);
            MainNode.Nodes.Add(SubNode);
            FillTreeViewNodes(Fol, SubNode, clientcontext);
        }
}

you can modify the code as per your requirement :-)

于 2012-07-18T10:27:54.260 回答