0

我有一個文檔庫。在文檔庫裏面我有一個名爲Studies的文件夾。在研究下,我還有10個文件夾和隨後的子文件夾。使用客戶端對象模型Sharepoint 2010填充Treeview

我需要使用客戶端對象模型的SharePoint來填充相同的樹視圖2010

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

我想在一個函數發佈此樹視圖,我可以通過文檔庫,並將其返回樹視圖。

回答

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

你可以修改代碼,按您的要求:-)

相關問題