Site Provisioning using PnP

Recently I got one requirement from one of my client that they want to re-use the artefacts of one site across multiple site instances. There were some other options but they have their own limitations. For ex: “Save Site as Template” option is not visible now in site settings in case of publishing sites.

So for this requirement we thought of going with “Site Provisioning” using PnP Provisioning engine.

You will find lot many examples on web which uses PnP core powershell extension but very few examples with C#.

In this post I first got the site artefacts using “GetProvisioningTemplate()” method then I used “ApplyProvisioningTemplate()” method to provision site. This code will work both for Team Site and Publishing site. I haven’t tested this with other site templates but it should work.

We need to add a NuGet package for PnP Library. So we can add “SharePointPnPCoreOnline” in our solution.

pnpcoreonline

By adding this NuGet, required methods for getting/applying provisioning template will be available.

I have used below method to create the template.

While executing above code I found out that page layouts and master pages were not downloaded but were present in the xml generated. So while applying template it was giving error. So to download the missing files I used the property “PersistPublishingFiles” of “ProvisioningTemplateCreationInformation” class.

I have used below method to Apply Template on new site.

I have saved the xml file generated at below location “C:\temp\pnpprovisioningdemo”, so I am providing this path while applying template. You can change this path as per your xml file location.

Hope this helps you in Site Provisioning. Happy Coding !!

References:

PnP-Guidance Provisioning

Pnp-Provisioning Sample

Advertisements