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; clientContext.Load(folder); // 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"); clientContext.ExecuteQuery();
Hope it helps you too.