Swetha

Swetha

  • NA
  • 196
  • 23.9k

"ExecuteQuery" with "0" args: "pageInfo.PageLayoutLisItem

Sep 6 2018 2:16 AM
I am getting exception while creating publishing page with pagelayout uisng powershell csom
 
Error:
Exception calling "ExecuteQuery" with "0" argument(s): "pageInformation.PageLayoutListItem"
 
No idea of what the error is.No error description. :-(
 
below is my code:
 
$siteUrl = $csvRow.SiteURL
$pageName= $csvRow.PageName
$pageLayoutName=$csvRow.PageLayout
$lists= $subsiteweb.Lists
$list=$lists.GetByTitle("Pages")
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'><Query><Where><Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>"+$pageName+"</Value></Contains></Where></Query></View>"
$listItems = $list.GetItems($query)
$subsiteCtx.Load($listItems)
$subsiteCtx.ExecuteQuery()
if($listItems.Count -le 0)
{
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = $credentials
$ctx.ExecuteQuery()
$pageLayoutList = $ctx.Web.Lists.GetByTitle("Master Page Gallery")
$pageLayoutQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$pageLayoutQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>"+$pageLayoutName+"</Value></Eq></Where></Query></View>"
$pageLayouts = $pageLayoutList.GetItems($pageLayoutQuery)
$ctx.Load($pageLayouts)
$ctx.ExecuteQuery()
$pageLayout = $pageLayouts[0]
#Get the publishing Web
$pubWeb = [Microsoft.SharePoint.Client.Publishing.PublishingWeb]::GetPublishingWeb($ctx, $ctx.Web)
$ctx.Load($pubWeb)
$pageInfo = New-Object Microsoft.SharePoint.Client.Publishing.PublishingPageInformation
$pageInfo.Name = $pageName
$pageInfo.PageLayoutListItem = $pageLayout
$page = $pubWeb.AddPublishingPage($pageInfo)
$ctx.Load($page)
$ctx.ExecuteQuery()
 
I tried finding out whether the $pageLayout object($pageLayout = $pageLayouts[0]) is empty and Yes it is empty ,but the exception I got is different.Can anyone explain what the error is and how should i resolve pls respond ASAP

Answers (1)