Create folder and sub folder inside document library using .Net client object model in SharePoint online

Create folder and sub folder inside document library using .Net client object model in SharePoint online

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.

Also read:
How to know which site definition being used by SharePoint 2016 site using SharePoint server object model?

SharePoint Online Delete all Items from list using JavaScript Object model

Create Content Type using JavaScript object model in SharePoint Online Office 365

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”);

fld1.Update();

fld2.Update();

clientContext.ExecuteQuery();

}


After running the code it will create a folder and sub folder inside the document library.

Create folder and sub folder inside document library using .Net client object model in SharePoint online
Create folder and sub folder inside document library using .Net client object model in SharePoint online

Hope this will help.


You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →