Skip to content

Instantly share code, notes, and snippets.

@bcameron1231
Last active December 13, 2018 18:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bcameron1231/db5160db9fa2e0ebc9ae5c677d00f53b to your computer and use it in GitHub Desktop.
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