Forum Discussion
Soheilsd
Jul 29, 2019Copper Contributor
Save as template again!!!
I am wondering if I can save a team site on SharePoint online as a template in a simple way??!! not using the PnP provisioning its too complicated... or is there a complete example of pnp code that...
- Jul 29, 2019Just wondering, why do you consider the PnP provisioning to be too complicated? You are looking for a solution from a Developer's perspective. With the PnP NuGet packages installed in your project, "Save as template" is basically just 1 line of code (web.GetProvisioningTemplate). Applying a template to another site is also just 1 line of code (web.ApplyProvisioningTemplate).
A sample console application using the above techniques can be found here:
https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/provisioning-console-application-sample
For SharePoint Online modern sites you can make use of Site Designs and Site Scripts. You could combine these with PnP provisioning as well.
https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-overview
Hope this helps!
Soheilsd
Jul 29, 2019Copper Contributor
what to write in my ApplyProvisioningTemplate?
the code opens up a console and it gets the template and target site and it works on them.
but what happens at the end is exactly what u said.
saurabhsachan
Jul 29, 2019Copper Contributor
Soheilsd wondering if you have used site designs. We can configure new sites based on templates.
https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-overview
- paulpaschaJul 29, 2019Bronze ContributorSomething like this should work:
private static void ApplyProvisioningTemplate(ConsoleColor defaultForeground, string targetWebUrl, string userName, SecureString pwd, ProvisioningTemplate template)
{
using (var ctx = new ClientContext(targetWebUrl))
{
ctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
ctx.Web.ApplyProvisioningTemplate(template);
}
}- SoheilsdJul 30, 2019Copper Contributor
thanks a lot it works perfectly.
- SoheilsdAug 17, 2019Copper Contributor
Hi my code were just doing fine until it gets this error at the end of it in the "web.ApplyProvisioningTemplate(template, ptai);" section:
error code:
“The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column.”
what should I do with that??!!