Hi @nellie ,
Please refer the following code snippet to create site page from custom template:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using ClientSidePage = OfficeDevPnP.Core.Pages.ClientSidePage;
using System.Security;
namespace CreatePageFromTemplate
{
class Program
{
static void Main(string[] args)
{
string userName = "user@Tenant.onmicrosoft.com";
string password = "**************";
using (ClientContext clientContext = new ClientContext("https://Tenant.sharepoint.com/sites/SiteName"))
{
SecureString securePassword = new SecureString();
foreach (char c in password.ToCharArray())
{
securePassword.AppendChar(c);
}
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
// Load the template page
ClientSidePage page = clientContext.Web.LoadClientSidePage("Templates/MyTemplate.aspx");
// Create and Save the modern page based on the template
page.Save("IT_Australia1.aspx");
}
}
}
}
After saving a page as template, SharePoint Online will create a folder named "Templates" to store the page template like this:
So get this template and then save into another page name will create the page based on this template.
Here is a detailed code demo, I suggest you can refer:
How to : Create modern page templates and provision modern pages using them via PnP PowerShell/Core
Thanks
Best Regards
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.