Question

Hello fellow sharepointers !

I need your help on my provisioning template.

I am creating a new Document library which is bound to a custom content Type. I want to add a whole architecture of folders and unfortunately can't make it work, i don't know why.

What i have :

my XML Template : GED_SiteLibrariesCreation.xml

<?xml version="1.0" encoding="utf-8" ?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2015/12/ProvisioningSchema">
  <pnp:Preferences></pnp:Preferences>
  <pnp:Templates>
    <pnp:ProvisioningTemplate ID="GED_SiteLibrariesCreation">
      <pnp:Lists>
          <pnp:ListInstance Title="Documents projet"
                          Description="Documents partagées entre les acteurs du projet (ASI et client)"
                          TemplateType="101"
                          Url="documentprojet"
                          EnableVersioning="true"
                          EnableMinorVersions="true"
                          MinorVersionLimit="20"
                          MaxVersionLimit="100"
                          DraftVersionVisibility="0"
                          ContentTypesEnabled="true"
                          RemoveExistingContentTypes="true"
                          EnableFolderCreation="true">
            <pnp:ContentTypeBindings>
              <pnp:ContentTypeBinding ContentTypeID="0x010100BBD2E6E36069334ABFD4717B8C2FA4D9" Default="true" />
              <pnp:ContentTypeBinding ContentTypeID="0x010100BBD2E6E36069334ABFD4717B8C2FA4D901"/>
              <pnp:ContentTypeBinding ContentTypeID="0x010100BBD2E6E36069334ABFD4717B8C2FA4D902"/>
            </pnp:ContentTypeBindings>
            <pnp:FieldDefaults>
              <pnp:FieldDefault FieldName="EtatValidation">Brouillon</pnp:FieldDefault>
              <pnp:FieldDefault FieldName="EtatValidationCR">A valider</pnp:FieldDefault>
            </pnp:FieldDefaults>

            <pnp:Folders>
              <pnp:Folder Name="01.TEST">
                  <pnp:Folder Name="0102. TEST"></pnp:Folder>
              </pnp:Folder>

            </pnp:Folders>
        </pnp:ListInstance>
 </pnp:Lists>
      
     
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

What do i get :

My list is created or updated, but no folder are created. I have absolutely no error nor output saying something went wrong.

I've followed letter to letter the examples given in the provisioning schema on GitHub

Please, could you give me other examples or a clue on what could go wrong ?

Thanks a lot.

Have a nice day.

Was it helpful?

Solution

I've tried your template and everything works fine for me - folders are created (I deleted ContentTypeBindings since this content types don't exist in my environment).

I can recommend the following:

  1. Make sure you are using latest version of PnP from nuget (I'm using SharePointPnPCoreOnline.2.9.1611.0)

  2. If #1 didn't help, try to remove all ContentTypeBindings like I did (may be that's an issue?)

UPD
So finally, thanks to @Gaelle comment, I was able to reproduce this behavior.
I found that there is a bug in PnP - here is the link to corresponding issue reported October, 20.
Following code will not work for you:

var ctx = new ClientContext("https://sp.sharepoint.com/sites/dev/");
var subweb = ctx.Site.OpenWeb("tests");
ctx.Load(subweb);
ctx.ExecuteQueryRetry();
.....
subweb.ApplyProvisioningTemplate(template);

Besides this one works:

var ctx = new ClientContext("https://sp.sharepoint.com/sites/dev/tests");
ctx.Load(ctx.Web);
ctx.ExecuteQueryRetry();
....
ctx.Web.ApplyProvisioningTemplate(template);

And this is what is the issue about: in the first sample I'm using OpenWeb method and it doesn't work, for second sample I created client context using sub site url and it does work.

For now I think this is the only working workaround for you - construct new client context (don't forget about disposing) for subsite.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top