Creating a publishing web part page

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.

How to do it...

Follow these steps to create a publishing web part page:

  1. Navigate to the site in your preferred web browser.
  2. Select Site contents from the Settings menu.
  3. Select the Pages library.
  4. Select New Document from the FILES tab in the ribbon as shown in the following screenshot:
    How to do it...
  5. Provide a title, description, and URL for the new page in the Title, Description, and URL fields.
  6. Select the (Welcome Page) Blank Web Part page template as shown in the following screenshot:
    How to do it...
  7. Click on Create.

How it works...

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.

There's more...

Publishing pages may also be created using PowerShell or code using the server-side object model.

Creating a publishing web part page using PowerShell

Follow these steps to create a publishing web part page using PowerShell:

  1. Get the site using the Get-SPWeb Cmdlet as follows:
    $web = Get-SPWeb "http://sharepoint/publishing"
    
  2. Get the publishing site from the SharePoint site as follows:
    $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    
  3. Get the page layout template from the publishing site using the following command:
    $layout = $pubWeb.GetAvailablePageLayouts() | Where-Object { $_.Title -eq "Blank Web Part Page" }
    
  4. Create a new publishing page as follows:
    $page = $pubWeb.AddPublishingPage("PowerShellPage.aspx", $layout)
    
  5. Update the publishing page object as follows:
    $page.Update()
    
  6. Set the Title property of the publishing page using the following commands:
    $page.ListItem["Title"] = "PowerShell Page" 
    
    $page.ListItem.Update()
    
  7. Use the Dispose method to discard the SPWeb object as follows:
    $web.Dispose()
    

Creating a publishing web part page with code using the server-side object model

Follow these steps to create a publishing web part page with code using the server-side object model:

  1. Open the site collection containing the site in a using statement as follows:
    using (var site = new SPSite("http://sharepoint/publishing"))
  2. Open the site in a using statement as follows:
    using (var web = site.OpenWeb())
  3. Get the publishing site from the SharePoint site as follows:
    var pubWeb = PublishingWeb.GetPublishingWeb(web);
  4. Get the page layout template from the publishing site using the following code:
    var layout = pubWeb.GetAvailablePageLayouts().Where(p => p.Title == "Blank Web Part Page").First();
  5. Create a new publishing page as follows:
    var page = pubWeb.AddPublishingPage("CodePage.aspx", layout);
  6. Update the publishing page object as follows:
    page.Update();
  7. Set the Title property of the publishing page using the following code:
    page.ListItem["Title"] = "Code Page";
    
    page.ListItem.Update();

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.85.181