Forum Discussion

David Grooms's avatar
David Grooms
Copper Contributor
Apr 25, 2017

PnP Provisioning template to automate sites

I'm currently using the XMLTemplateProvider class to load an xml template and apply it to the site. This works fine.

The issue is that this interface only takes a file and I'd like to store the model templates in a SharePoint list.

 

So I have to read the bytes from SharePoint and write a local temp file then delete it when the provisioning is complete.

 

I saw the class SPSiteTemplateManager

 

it looked like this might be able to load the template directly from a SharePoint list, but I haven't found any additional information on how I might use this.

 

Is this feasable and if so is there any kind of sampel code or documentation around this ?

 

Thanks

3 Replies

  • Have you looked at the code in the PnP Partner Pack for provisioning? They create an Infrastructure site collection and store all the PnP provisioning template XML files in doc libraries.

     

    https://github.com/SharePoint/PnP-Partner-Pack

     

    You can still use the XMLTemplateProvider, but instead of the XMLFileSystemTemplateProvider, use the XMLSharePointTemplateProvider (part of https://github.com/SharePoint/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Framework/Provisioning/Providers/Xml/XMLSharePointTemplateProvider.cs) and pass in context, Web URL and ensure the list item has a File property.

    Then using the ProvisioningTemplate class to to hold the template from the XML provider using the provider.GetTemplate(item.File.Name) method. 

    ProvisioningTemplate template = provider.GetTemplate(item.File.Name);

    You can look at the source code starting at line 50 - 111

    https://github.com/SharePoint/PnP-Partner-Pack/blob/master/OfficeDevPnP.PartnerPack.SiteProvisioning/OfficeDevPnP.PartnerPack.Infrastructure/SharePoint/SharePointProvisioningRepository.cs

     

    Thanks

     

Resources