How can one create a document library from custom library template with Folder structure inside using CSOM?

I have created my template and when creating an instance of that manually folders are created. The challenge is when doing it programatically the folder structure doesn't show.

This is what I have thus far:

var listTemplate = clientContext.Site.GetCustomListTemplates(clientContext.Site.RootWeb).GetByName("Test");

clientContext.Load(listTemplate, lt=> lt.Name, lt => lt.FeatureId, lt => lt.ListTemplateTypeKind);

listCreationInfo.TemplateFeatureId = listTemplate.FeatureId;
listCreationInfo.TemplateType = listTemplate.ListTemplateTypeKind;

List newList = oWeb.Lists.Add(listCreationInfo);
newList.EnableFolderCreation = true;
newList.ContentTypesEnabled = true;


Any help would be appreciated.

1 Answer 1


Make sure the custom library template include content, and then using the code below to create new library base on the custom library template.

string siteUrl = "https://tenant.sharepoint.com/sites/lz";
var login = "[email protected]";
var password = "xx";

ClientContext clientContext = new ClientContext(siteUrl);
var securePassword = new SecureString();
foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials(login, securePassword);

var listTemplate = clientContext.Site.GetCustomListTemplates(clientContext.Site.RootWeb).GetByName("Test");

clientContext.Load(listTemplate, lt => lt.Name, lt => lt.FeatureId, lt => lt.ListTemplateTypeKind);

ListCreationInformation listCreationInfo = new ListCreationInformation();
listCreationInfo.Title = "NewTestLibrary";
listCreationInfo.ListTemplate = listTemplate;
List newList = clientContext.Web.Lists.Add(listCreationInfo);

newList.ContentTypesEnabled = true;
  • If my reply help you, please mark the reply as answer, thanks.
    – LZ_MSFT
    Commented Jan 18, 2019 at 1:26

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.