In this post we will discuss how we can create folders and sub folders inside a document library in SharePoint online using .Net managed client object model code. Here I have a SharePoint document library and by using client side code we will create a folder and within that folder we will also create another sub folder.
Here we are doing this using a Windows application and I have used Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dlls.
– How to know which site definition being used by SharePoint 2016 site using SharePoint server object model?
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 be 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.