Swetha

Swetha

  • NA
  • 196
  • 25.9k

Err :“the given key was not present in the dictionary ” SPO

Sep 17 2018 12:59 AM
Hi,
I am unable to create a publishing page in any of the subsites,gettingerror:"the given key was not present in the dictionary". but able to create in site collection level.
 
Below is my Code:
 
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($ParentSiteurl)
$ctx.Credentials = $credentials
$ctx.ExecuteQuery()
$subsiteCtx = New-Object Microsoft.SharePoint.Client.ClientContext($subsiteUrl)
$subsiteCtx.Credentials = $credentials
$subsiteCtx.ExecuteQuery()
$pageLayoutList = $ctx.Web.Lists.GetByTitle("Master Page Gallery")
$ctx.Load($pageLayoutList)
$ctx.ExecuteQuery()
$pageLayoutQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$pageLayoutQuery.ViewXml = "OneSmallOneLargeOneSmallColumnLayout.aspx"
$pageLayouts = $pageLayoutList.GetItems($pageLayoutQuery)
$ctx.Load($pageLayouts)
$ctx.ExecuteQuery()
 
$pageLayout = $pageLayouts[0]
#Get the publishing Web
$pubWeb = [Microsoft.SharePoint.Client.Publishing.PublishingWeb]::GetPublishingWeb($subsiteCtx, $subsiteCtx.Web)
$subsiteCtx.Load($pubWeb)
$subsiteCtx.ExecuteQuery()
$pageInfo = New-Object Microsoft.SharePoint.Client.Publishing.PublishingPageInformation
$pageInfo.Name = $pageName
$pageInfo.PageLayoutListItem =$pageLayout
$page =$pubWeb.AddPublishingPage($pageInfo)
$subsiteCtx.Load($page)
$subsiteCtx.ExecuteQuery()
$PagesList = $subsiteCtx.Web.Lists.GetByTitle("Pages")
$subsiteCtx.Load($PagesList)
$subsiteCtx.ExecuteQuery()
$publishPage = $subsiteCtx.Web.GetFileByServerRelativeUrl($PagesList.ParentWebUrl + "/Pages/" + $pageName)
$subsiteCtx.Load($publishPage)
$subsiteCtx.ExecuteQuery()
$publishPage.CheckIn("Page Created", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
$publishPage.publish("Publish")
$subsiteCtx.load($publishPage)
$subsiteCtx.ExecuteQuery()
 

Answers (3)