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 :-)