Forum Discussion

Paul Quirk's avatar
Paul Quirk
Copper Contributor
Aug 03, 2017

Add to PnP Provisioning template using CSOM

I am currently creating a console application using the PnP provisioning engine.   I'd like to be able to add a list to the template in memory using CSOM as per this example   template.Lists.Add(...
  • paulpascha's avatar
    paulpascha
    Aug 04, 2017

    OK, see the changes I've made below.

     

    You should implement FindDocumentLibraries to get the document libraries in your site. I think you can either use list.RemoveExistingContentTypes or remove the existing Content Type through a ContentTypeBinding (both included in my code below).

     

    In addition to everything required, you should also initialize the list variable further to reflect your existing Document Library's configuration to prevent undesired changes after applying your template.

     

    var documentLibraries = FindDocumentLibraries();
    var template = new ProvisioningTemplate();
    
    foreach (var documentLibrary in documentLibraries)
    {
         var list = new ListInstance();
    list.RemoveExistingContentTypes = true;
    var listContentTypeToAdd = new ContentTypeBinding(); listContentTypeToAdd.Default = true; listContentTypeToAdd.ContentTypeId = "0x01010003860C260AF340CB8B30D74959AB0FC4" // Custom Document var listContentTypeToRemove = new ContentTypeBinding(); listContentTypeToRemove.Remove = true; listContentTypeToRemove.ContentTypeId = "0x0101"; // Document list.ContentTypeBindings.Add(listContentTypeToAdd); list.ContentTypeBindings.Add(listContentTypeToRemove); template.Lists.Add(list); }

     Hope this helps!

Resources