In this article, you will learn how to deploy a page layout, using PnP Client Side Object Model code.
The page layout can be created manually in many ways. The page layouts can be deployed manually or using the deployment tools built , using programming languages. Here, let us see how the page layouts can be deployed, using PnP CSOM programming language.
If you are new to PnP programming, please refer to the ebook on PnP CSOM programming, which has the introduction, basics and samples on PnP CSOM programming.
Microsoft Visual Studio
SharePoint Online portal
Page layouts can be of multiple types. They are article pages, publishing pages, welcome pages etc. Each of the page layouts are associated with a content type. All the page layouts are differentiated, using content type id. The screen shot given below shows the page of the available content types (Content types page - /_layouts/15/mngctype.aspx).
Custom page layouts can be built, using the existing content types. These existing content types are called as associated content types, while creating a custom page layout.
Create a page layout manually, using the editors or modify the existing page layout by downloading from the site.
Create a new console Application and install the packages required for PnP CSOM programming, using NuGet Package Manager. (The detailed steps to create a project has been explained in the ebook mentioned above).
Create the layout, using DeployPageLayout command. The required input parameters are source file path, title, description, associate content type id.
The content type ID of the page layouts can be identified from the content type page (/_layouts/15/mngctype.aspx). For example, to get the content type ID of article page layout, click the article page content type. The ID can be extracted from the URL (ctype parameter).
In the sample given below, you can find the PnP CSOM code snippet to deploy the custom publishing page layout.
AuthenticationManager authManager = new AuthenticationManager();
// Get and set the client context
// Connects to SharePoint online site using inputs provided
using (var clientContext = authManager.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
string sourceFilePath = @"D:\Workspace\Nakkeeran\CustomArticleLayout.aspx";
string title = "CustomArticleLayout";
string description = "Layout for custom article pages";
string pubpagelayoutCID = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D";
clientContext.Web.DeployPageLayout(sourceFilePath, title, description, pubpagelayoutCID);
Console.WriteLine("Page Layout successfully deployed");
catch (Exception ex)
Console.WriteLine("Error Message: " + ex.Message);
From the console Application, run the code by pressing F5 and you can see the success/error details on the command prompt.
The snapshot given below (Page creation screen) shows the custom article page layout created, using PnP Core CSOM programming, which is ready for use. The pages can be created, using the layout. Likewise, other page layouts can also be created.
Thus, you have seen the basics and steps to deploy the page layout, using PnP core CSOM programming.