How to create folders and subfolders in SharePoint document library using client object model?

For example:

   Andhra pradesh
        Hitech City

1 Answer 1


How to create Folder (including nested) via CSOM in SharePoint 2010/2013

/// <summary>
/// Create Folder client object
/// </summary>
/// <param name="web"></param>
/// <param name="listTitle"></param>
/// <param name="fullFolderUrl"></param>
/// <returns></returns>
public static Folder CreateFolder(Web web, string listTitle, string fullFolderUrl)
    if (string.IsNullOrEmpty(fullFolderUrl))
        throw new ArgumentNullException("fullFolderUrl");
    var list = web.Lists.GetByTitle(listTitle);
    return CreateFolderInternal(web, list.RootFolder, fullFolderUrl);

private static Folder CreateFolderInternal(Web web, Folder parentFolder, string fullFolderUrl)
    var folderUrls = fullFolderUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
    string folderUrl = folderUrls[0];
    var curFolder = parentFolder.Folders.Add(folderUrl);

    if (folderUrls.Length > 1)
        var subFolderUrl = string.Join("/", folderUrls, 1, folderUrls.Length - 1);
        return CreateFolderInternal(web, curFolder, subFolderUrl);
    return curFolder;


Assume the following folder structure has to be created in Documents library:

 - Archive
 --- 2008
   --- 09

The example demonstrates how to create the specified folder structure:

 using (var ctx = new ClientContext(siteUrl))
     var folder = CreateFolder(ctx.Web, "Documents", "Archive/2008/09");
  • Is it possible to achieve the same ( create the nested structure of folders and subfolders) using ecma script / jsom
    – samolpp2
    Commented Feb 21, 2018 at 13:01
  • 1
    @SaMolPP, surely! Basically this script could be converted or if you have a more specific requirements It might be a good idea to create a separate question Commented Feb 21, 2018 at 13:03
  • Vadim, i have posted a new question/thread on this using ECMA script , please throw some light on that question sharepoint.stackexchange.com/questions/237907/…
    – samolpp2
    Commented Mar 15, 2018 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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