Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using (var ctx = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(newSiteUrl, clientId, clientSecret))
{
var pages = ctx.Web.Lists.GetByTitle("Site Pages");
ctx.Load(pages);
//get template page
var templatePage = pages.RootFolder.GetFile("Project-Home.aspx").ListItemAllFields;
ctx.Load(templatePage);
ctx.ExecuteQuery();
//this is our template page content
var _customPageHeader = templatePage[ClientSidePage.PageLayoutContentField]; //LayoutWebpartsContent
var _canvasContent = templatePage["CanvasContent1"];
//create new page in site page library
var item = pages.RootFolder.Files.AddTemplateFile("/sites/test/sitepages/BeauTest.aspx", TemplateFileType.ClientSidePage).ListItemAllFields;
//update page header from template information
item[ClientSidePage.PageLayoutContentField] = _customPageHeader;
item[ClientSidePage.ClientSideApplicationId] = ClientSidePage.SitePagesFeatureId; //ClientSideApplicationId - b6917cb1-93a0-4b97-a84d-7cf49975d4ec
item["CanvasContent1"] = _canvasContent; //"<div></div>";
item["_TopicHeader"] = "Service Line";
item.Update();
ctx.Load(item);
ctx.ExecuteQuery();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.