0

I have a SharePoint site that I am using as a template to create new SharePoint sites.

This site contains document libraries that include empty folders:

enter image description here

However, the site that gets created from the template does not include any folders in the document libraries:

enter image description here

I'm using PNP.Framework 1.9 to generate the template:

 using var context = await GetAndLoadCsomClientContext(templateSiteUrl);

    var handlersToProcess = _sharePointSettings
        .DefaultTemplateHandlers
        .Aggregate((result, item) => result | item);

    var creationInformation = new ProvisioningTemplateCreationInformation(context.Web)
    {
        HandlersToProcess = handlersToProcess,
        IncludeSiteGroups = true,
        IncludeTermGroupsSecurity = true,
        IncludeSiteCollectionTermGroup = true,
        IncludeSearchConfiguration = true,
        IncludeAllClientSidePages = true,
        ProgressDelegate = (message, step, total) =>
        {
            _logger.LogInformation($"Template Retrieval Progress: {step}/{total} - {message}");
        }
    };

    var template = context.Web.GetProvisioningTemplate(creationInformation);

and apply the template to the newly created site:

 using var context = await GetAndLoadCsomClientContext(siteCollectionUrl);

    var provisioningTemplateInformation = new ProvisioningTemplateApplyingInformation()
    {
        // Delay to wait for site creation SharePoint still performs tasks even though it says it's ready
        DelayAfterModernSiteCreation = _functionSettings.ProvisioningSecondsDelayAfterSiteCreation,
        MessagesDelegate = (message, ProvisioningMessageType) =>
        {
            _logger.LogInformation($"Provisioning Messages: {message}. Type: {ProvisioningMessageType}");
        },
        ProgressDelegate = (message, step, total) =>
        {
            _logger.LogInformation($"Provisioning Progress: {step}/{total} - {message}");
        }
    };

    context.Web.ApplyProvisioningTemplate(provisionUsingTemplate, provisioningTemplateInformation);

The template gets applied correctly, it's just that the template doesn't include any folders under the lists. If I manually add folders to the lists in the template, those folders get created.

New contributor
David Kethel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

2 Answers 2

0

The Provisioning system handles the list and the pieces of the list (views, content types, fields etc.) but doesn't seem to be able to include content. Folders would be content.

I would suggest creating a script to add the folders such as:

Add-PnPFolder -Name NewFolder -Folder "Shared Documents"

This would create a folder called NewFolder in the Documents library of the connected site.

0

I agree with MunkeyWrench's answer, it unable to include folders, you can create folders by adding them manually.

======================================================================

If the answer is helpful, please click "√" on the left panel of the answer and kindly upvote it.

1
  • Please don't add "thanks" or "this works" as answers. This could be an appropriate post if we were a discussion forum, but we're a Q&A site; answers must provide an answer to the question. Please take a moment to read the tour; invest some time in the site and you will gain sufficient privileges to upvote answers you like, which is the SharePoint way of saying thank you. Or pay it forward.
    – Glorfindel
    5 hours ago

Your Answer

David Kethel is a new contributor. Be nice, and check out our Code of Conduct.

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.