Class PageExtensions
Class that handles all page and web part related operations
Inheritance
Namespace: Microsoft.SharePoint.Client
Assembly: PnP.Framework.dll
Syntax
public static class PageExtensions : object
Methods
AddClientSidePage(Web, String, Boolean)
Adds a client side "modern" page to a "classic" or "modern" site
Declaration
public static IPage AddClientSidePage(this Web web, string pageName = "", bool alreadyPersist = false)
Parameters
Web
web
Web to add the page to |
System.String
pageName
Name (e.g. demo.aspx) of the page to be added |
System.Boolean
alreadyPersist
Already persist the created, empty, page before returning the instantiated ClientSidePage instance |
Returns
IPage
A ClientSidePage instance |
AddClientSidePageAsync(Web, String, Boolean)
Adds a client side "modern" page to a "classic" or "modern" site
Declaration
public static async Task<IPage> AddClientSidePageAsync(this Web web, string pageName = "", bool alreadyPersist = false)
Parameters
Web
web
Web to add the page to |
System.String
pageName
Name (e.g. demo.aspx) of the page to be added |
System.Boolean
alreadyPersist
Already persist the created, empty, page before returning the instantiated ClientSidePage instance |
Returns
Task<IPage>
A ClientSidePage instance |
AddHtmlToWikiPage(Web, String, String)
Add HTML to a wiki page
Declaration
public static void AddHtmlToWikiPage(this Web web, string serverRelativePageUrl, string html)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
Server relative URL of the page to add html to |
System.String
html
|
AddHtmlToWikiPage(Web, String, String, Int32, Int32)
Add a HTML fragment to a location on a wiki style page
Declaration
public static void AddHtmlToWikiPage(this Web web, string serverRelativePageUrl, string html, int row, int col)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
server relative Url of the page to add the fragment to |
System.String
html
html to be inserted |
System.Int32
row
Row of the wiki table that should hold the inserted web part |
System.Int32
col
Column of the wiki table that should hold the inserted web part |
AddHtmlToWikiPage(Web, String, String, String)
Add html to a wiki style page
Declaration
public static void AddHtmlToWikiPage(this Web web, string folder, string html, string page)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
folder
System name of the wiki page library - typically sitepages |
System.String
html
The html to insert |
System.String
page
Page to add the html on |
AddHtmlToWikiPage(Web, String, String, String, Int32, Int32)
Add a HTML fragment to a location on a wiki style page
Declaration
public static void AddHtmlToWikiPage(this Web web, string folder, string html, string page, int row, int col)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
folder
System name of the wiki page library - typically sitepages |
System.String
html
html to be inserted |
System.String
page
Page to add the web part on |
System.Int32
row
Row of the wiki table that should hold the inserted web part |
System.Int32
col
Column of the wiki table that should hold the inserted web part |
AddLayoutToWikiPage(Web, WikiPageLayout, String)
Applies a layout to a wiki page
Declaration
public static void AddLayoutToWikiPage(this Web web, WikiPageLayout layout, string serverRelativePageUrl)
Parameters
Web
web
Site to be processed - can be root web or sub site |
WikiPageLayout
layout
Wiki page layout to be applied |
System.String
serverRelativePageUrl
Server relative URL of the page to add the layout to |
AddLayoutToWikiPage(Web, String, WikiPageLayout, String)
Applies a layout to a wiki page
Declaration
public static void AddLayoutToWikiPage(this Web web, string folder, WikiPageLayout layout, string page)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
folder
System name of the wiki page library - typically sitepages |
WikiPageLayout
layout
Wiki page layout to be applied |
System.String
page
Name of the page that will get a new wiki page layout |
AddNavigationFriendlyUrl(PublishingPage, Web, String, String, NavigationTermSetItem, Boolean, Boolean)
Adds a user-friendly URL for a PublishingPage object.
Declaration
public static string AddNavigationFriendlyUrl(this PublishingPage page, Web web, string navigationTitle, string friendlyUrlSegment, NavigationTermSetItem editableParent, bool showInGlobalNavigation = true, bool showInCurrentNavigation = true)
Parameters
PublishingPage
page
The target page to add to managed navigation. |
Web
web
The target web. |
System.String
navigationTitle
The title for the navigation item. |
System.String
friendlyUrlSegment
The user-friendly text to use as the URL segment. |
NavigationTermSetItem
editableParent
The parent NavigationTermSetItem object below which this new friendly URL should be created. |
System.Boolean
showInGlobalNavigation
Defines whether the navigation item has to be shown in the Global Navigation, optional and default to true. |
System.Boolean
showInCurrentNavigation
Defines whether the navigation item has to be shown in the Current Navigation, optional and default to true. |
Returns
System.String
The simple link URL just created. |
AddWebPartToWebPartPage(Web, WebPartEntity, String)
Inserts a web part on a web part page
Declaration
public static WebPartDefinition AddWebPartToWebPartPage(this Web web, WebPartEntity webPart, string page)
Parameters
Web
web
Site to be processed - can be root web or sub site |
WebPartEntity
webPart
Information about the web part to insert |
System.String
page
Page to add the web part on |
Returns
WebPartDefinition
Returns the added |
AddWebPartToWebPartPage(Web, String, WebPartEntity)
Inserts a web part on a web part page
Declaration
public static WebPartDefinition AddWebPartToWebPartPage(this Web web, string serverRelativePageUrl, WebPartEntity webPart)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
Page to add the web part on |
WebPartEntity
webPart
Information about the web part to insert |
Returns
WebPartDefinition
Returns the added |
AddWebPartToWikiPage(Web, String, WebPartEntity, Int32, Int32, Boolean)
Add web part to a wiki style page
Declaration
public static WebPartDefinition AddWebPartToWikiPage(this Web web, string serverRelativePageUrl, WebPartEntity webPart, int row, int col, bool addSpace)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
Server relative URL of the page to add the webpart to |
WebPartEntity
webPart
Information about the web part to insert |
System.Int32
row
Row of the wiki table that should hold the inserted web part |
System.Int32
col
Column of the wiki table that should hold the inserted web part |
System.Boolean
addSpace
Does a blank line need to be added after the web part (to space web parts) |
Returns
WebPartDefinition
Returns the added |
AddWebPartToWikiPage(Web, String, WebPartEntity, String, Int32, Int32, Boolean)
Add web part to a wiki style page
Declaration
public static WebPartDefinition AddWebPartToWikiPage(this Web web, string folder, WebPartEntity webPart, string page, int row, int col, bool addSpace)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
folder
System name of the wiki page library - typically sitepages |
WebPartEntity
webPart
Information about the web part to insert |
System.String
page
Page to add the web part on |
System.Int32
row
Row of the wiki table that should hold the inserted web part |
System.Int32
col
Column of the wiki table that should hold the inserted web part |
System.Boolean
addSpace
Does a blank line need to be added after the web part (to space web parts) |
Returns
WebPartDefinition
Returns the added |
AddWikiPage(Web, String, String)
Adds a blank Wiki page to the site pages library
Declaration
public static string AddWikiPage(this Web web, string wikiPageLibraryName, string wikiPageName)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
wikiPageLibraryName
Name of the wiki page library |
System.String
wikiPageName
Wiki page to operate on |
Returns
System.String
The relative URL of the added wiki page |
AddWikiPageByUrl(Web, String, String)
Adds a wiki page by Url
Declaration
public static void AddWikiPageByUrl(this Web web, string serverRelativePageUrl, string html = null)
Parameters
Web
web
The web to process |
System.String
serverRelativePageUrl
Server relative URL of the wiki page to process |
System.String
html
HTML to add to wiki page |
DeleteWebPart(Web, String, String)
Deletes a web part from a page
Declaration
public static void DeleteWebPart(this Web web, string serverRelativePageUrl, string title)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
Server relative URL of the page to remove |
System.String
title
Title of the web part that needs to be deleted |
DeleteWebPart(Web, String, String, String)
Deletes a web part from a page
Declaration
public static void DeleteWebPart(this Web web, string folder, string title, string page)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
folder
System name of the wiki page library - typically sitepages |
System.String
title
Title of the web part that needs to be deleted |
System.String
page
Page to remove the web part from |
EnsureWikiPage(Web, String, String)
Returns the Url for the requested wiki page, creates it if the pageis not yet available
Declaration
public static string EnsureWikiPage(this Web web, string wikiPageLibraryName, string wikiPageName)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
wikiPageLibraryName
Name of the wiki page library |
System.String
wikiPageName
Wiki page to operate on |
Returns
System.String
The relative URL of the added wiki page |
GetWebPartProperties(Web, Guid, String)
Returns web part properties
Declaration
public static PropertyValues GetWebPartProperties(this Web web, Guid id, string serverRelativePageUrl)
Parameters
Web
web
The web to process |
Guid
id
The id of the webpart |
System.String
serverRelativePageUrl
|
Returns
PropertyValues
|
GetWebParts(Web, String)
List the web parts on a page
Declaration
public static IEnumerable<WebPartDefinition> GetWebParts(this Web web, string serverRelativePageUrl)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
Server relative URL of the page containing the webparts |
Returns
IEnumerable<WebPartDefinition>
|
GetWebPartXml(Web, Guid, String)
Gets XML string of a Webpart
Declaration
public static string GetWebPartXml(this Web web, Guid webPartId, string serverRelativePageUrl)
Parameters
Web
web
Site to be processed - can be root web or sub site |
Guid
webPartId
The id of the webpart |
System.String
serverRelativePageUrl
Server relative URL of the page to add the xml to |
Returns
System.String
Returns XML string of a Webpart |
GetWikiPageContent(Web, String)
Gets the HTML contents of a wiki page
Declaration
public static string GetWikiPageContent(this Web web, string serverRelativePageUrl)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System.String
serverRelativePageUrl
Server relative URL of the page, e.g. /sites/demo/SitePages/Test.aspx |
Returns
System.String
Returns the HTML contents of a wiki page |
LoadClientSidePage(Web, String)
Loads a client side "modern" page
Declaration
public static IPage LoadClientSidePage(this Web web, string pageName)
Parameters
Web
web
Web to load the page from |
System.String
pageName
Name (e.g. demo.aspx) of the page to be loaded |
Returns
IPage
A ClientSidePage instance |
LoadClientSidePageAsync(Web, String)
Loads a client side "modern" page
Declaration
public static async Task<IPage> LoadClientSidePageAsync(this Web web, string pageName)
Parameters
Web
web
Web to load the page from |
System.String
pageName
Name (e.g. demo.aspx) of the page to be loaded |
Returns
Task<IPage>
A ClientSidePage instance |
SetWebPartProperty(Web, String, Boolean, Guid, String)
Sets a web part property
Declaration
public static void SetWebPartProperty(this Web web, string key, bool value, Guid id, string serverRelativePageUrl)
Parameters
Web
web
The web to process |
System.String
key
The key to update |
System.Boolean
value
The value to set |
Guid
id
The id of the webpart |
System.String
serverRelativePageUrl
Server relative URL of the page to set web part property |
SetWebPartProperty(Web, String, Int32, Guid, String)
Sets a web part property
Declaration
public static void SetWebPartProperty(this Web web, string key, int value, Guid id, string serverRelativePageUrl)
Parameters
Web
web
The web to process |
System.String
key
The key to update |
System.Int32
value
The value to set |
Guid
id
The id of the webpart |
System.String
serverRelativePageUrl
Server relative URL of the page to set web part property |
SetWebPartProperty(Web, String, String, Guid, String)
Sets a web part property
Declaration
public static void SetWebPartProperty(this Web web, string key, string value, Guid id, string serverRelativePageUrl)
Parameters
Web
web
The web to process |
System.String
key
The key to update |
System.String
value
The value to set |
Guid
id
The id of the webpart |
System.String
serverRelativePageUrl
Server relative URL of the page to set web part property |