0

문서 라이브러리가 있습니다. 문서 라이브러리 안에는 Studies라는 폴더가 있습니다. 연구 중에 나는 10 개의 폴더와 후속 하위 폴더도 가지고 있습니다.클라이언트 개체 모델 Sharepoint 2010을 사용하여 트리 뷰 채우기

나는 클라이언트 개체 모델 셰어를 사용하여 트리보기에서 같은를 채울 필요가 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); 
     } 
} 

각 도서관의 모든 라이브러리 및 폴더를 표시합니다 다음 코드