0

ドキュメント ライブラリがあります。ドキュメント ライブラリ内に、Study というフォルダーがあります。調査中、10 個のフォルダーとそれに続くサブフォルダーもあります。

クライアント オブジェクト モデル SharePoint 2010 を使用して、同じものをツリー ビューに表示する必要があります。

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

ドキュメント ライブラリを渡すことができる関数でこれをツリー ビューで公開し、ツリー ビューを返します。

4

1 に答える 1

0

次のコードは、各ライブラリのすべてのライブラリとフォルダを表示します

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

要件に応じてコードを変更できます:-)

于 2012-07-18T10:27:54.260 に答える