My document library has a folder labeled "clients". What I would like to happen; every time I create a new "Client Name" folder within clients, how do I get subfolders to automatically generate? For example, John Smith's file has "Orders", "Plaintiff filings", "Defendant filings", etc. I want those to automatically generate when I create a client file.


The below CSOM code worked for me.

List list = clientContext.Web.Lists.GetByTitle("My List");

var folder = list.RootFolder;

// This will create the Root Folder in the library
folder = folder.Folders.Add("Parent-Folder");  

//This will create the sub-folder inside the folder created from above code
var nestedFolder = folder.Folders.Add("Child1-Folder");

Hope it helps you too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.