magritton
2/25/2015 - 6:30 PM

This list the folders and sub folders of a document library using the client object model in SharePoint 2013

This list the folders and sub folders of a document library using the client object model in SharePoint 2013

public void SendToSp()
        {
            ClientContext ci = new ClientContext("http://portal.opwftg.com/sites/OPWSS/Teams/OCM/OCM Backup");
            List l = ci.Web.Lists.GetByTitle("PF");
            FolderCollection folderCollection = ci.Web.GetFolderByServerRelativeUrl("pf").Folders;
            ci.Load(folderCollection);
            ci.ExecuteQuery();

            foreach (Folder item in folderCollection)
            {
                Console.WriteLine(item.ServerRelativeUrl);
                getFolders(item.ServerRelativeUrl);
            }
        }

        private void getFolders(string strUrl)
        {
            ClientContext ci = new ClientContext("http://portal.opwftg.com/sites/OPWSS/Teams/OCM/OCM Backup");
            FolderCollection folderCollection = ci.Web.GetFolderByServerRelativeUrl(strUrl).Folders;
            ci.Load(folderCollection);
            ci.ExecuteQuery();

            foreach (Folder item in folderCollection)
            {
                Console.WriteLine(item.ServerRelativeUrl);
                getFolders(item.ServerRelativeUrl);
            }
        }