SharePoint provides many page layouts that serve as templates when creating content pages. In this recipe, we will use the Blank Web Part page template to create a new content page.
Follow these steps to create a publishing web part page:
Pages in a SharePoint library are created with a page layout template. This template provides the general layout of the content within the confines of the master page.
Publishing pages may also be created using PowerShell or code using the server-side object model.
Follow these steps to create a publishing web part page using PowerShell:
Get-SPWeb
Cmdlet as follows:$web = Get-SPWeb "http://sharepoint/publishing"
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$layout = $pubWeb.GetAvailablePageLayouts() | Where-Object { $_.Title -eq "Blank Web Part Page" }
$page = $pubWeb.AddPublishingPage("PowerShellPage.aspx", $layout)
$page.Update()
Title
property of the publishing page using the following commands:$page.ListItem["Title"] = "PowerShell Page" $page.ListItem.Update()
Dispose
method to discard the SPWeb
object as follows:$web.Dispose()
Follow these steps to create a publishing web part page with code using the server-side object model:
using
statement as follows:using (var site = new SPSite("http://sharepoint/publishing"))
using
statement as follows:using (var web = site.OpenWeb())
var pubWeb = PublishingWeb.GetPublishingWeb(web);
var layout = pubWeb.GetAvailablePageLayouts().Where(p => p.Title == "Blank Web Part Page").First();
var page = pubWeb.AddPublishingPage("CodePage.aspx", layout);
page.Update();
Title
property of the publishing page using the following code:page.ListItem["Title"] = "Code Page"; page.ListItem.Update();
3.147.85.181