In this post, we will discuss how we can create folders and subfolders inside a document library in SharePoint online using.Net managed client object model code. Here I have a SharePoint document library and by using the client-side code we will create a folder and within that folder, we will also create another subfolder.
Here we are doing this using a Windows application and I have used Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dlls.
Below is the full code.
using (ClientContext clientContext = new ClientContext(“https://onlysharepoint2013.sharepoint.com/sites/Bhawana/”))
SecureString passWord = new SecureString();
foreach (char c in “********”.ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials(“bijay@OnlySharePoint2013.onmicrosoft.com”, passWord);
var web = clientContext.Web;
var lst = web.Lists.GetByTitle(“MyDemoDocuments”);
var fld1 = lst.RootFolder.Folders.Add(“FirstLevel1”);
var fld2 = fld1.Folders.Add(“SecondLevel2”);
After running the code it will create a folder and sub folder inside the document library.
Hope this will help.
Download FREE SharePoint 2019 Installation PDF Guide
This FREE PDF contains, Steps by step guide to install SharePoint 2019 Preview, prerequisites, hardware and software new features. First impression to SharePoint Server 2019 new modern site, modern lists and modern document libraries.
You May Also like the Following SharePoint Online Tutorials: