Forum Discussion
How to create Repost Page (Modern Page Library) with PowerShell
- Oct 12, 2018
Dear all,
I finally found how to do the Repost Page Creation with CSOM only.
The missing parts were the page layout to load correctly the page in edit mode, the PromotedState to be sure it will be considered as a news and the last ID to know exactly the target:
- ["_OriginalSourceSiteId"]
- ["_OriginalSourceWebId"]
- ["_OriginalSourceListId"]
- ["_OriginalSourceItemId"]
The code has to be similar to the following one:
$NewPageitem["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118002A50BFCFB7614729B56886FADA02339B00874A802FBA36B64BAB7A47514EAAB232"; $NewPageitem["PageLayoutType"] = "RepostPage" $NewPageitem["PromotedState"] = "2" $NewPageitem["Title"] = $CSVItem.NewsTitle $NewPageitem["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" $NewPageitem["_OriginalSourceSiteId"] = $MyDestinationPageSiteColl.ID $NewPageitem["_OriginalSourceWebId"] = $MyDestinationPageweb.ID $NewPageitem["_OriginalSourceListId"] = $MyDestinationPagelist.ID $NewPageitem["_OriginalSourceItemId"] = $MyDestinationPageFileitem["UniqueId"].ToString() $NewPageitem["_OriginalSourceUrl"] = $MyCSVNewsURL $NewPageitem["Editor"] = $MyEditoruserAccount.Id $NewPageitem["Author"] = $MyEditoruserAccount.Id $NewPageitem["Description"] = $MyCSVNewsDescription $NewPageitem["BannerImageUrl"] = $MyCSVNewsPictureURL; $NewPageitem["Modified"] = $MyCSVPublishingDate; $NewPageitem["Created"] = $MyCSVPublishingDate; $NewPageitem["Created_x0020_By"] = $MyEditoruserAccount.LoginName $NewPageitem["Modified_x0020_By"] = $MyEditoruserAccount.LoginName $NewPageitem["FirstPublishedDate"] = $MyCSVPublishingDate; $NewPageitem.Update(); $MyctxTemp.Load($NewPageitem); $MyctxTemp.ExecuteQuery();
It's now working perfectly and the only point i'm fighting with is the picture display.
Thanks a lot for your help
Fab
Thanks a lot Bert for your message.
I looked the option to use the PnP to create that Repost Page, but the command available into PnP is not supporting the Repost Content Type
$page = Add-PnPClientSidePage -Name $pagename -LayoutType Home
The layouts are talking only the model to use into the modern page (Site Page), but the Repost is a dedicated Content Type.
This is why I started with the basic CSOM command instead.
Fab
Adding content type support when provisioning client side pages is something we do have in the PnP backlog...but in the meanwhile did you try the following:
- create page using default content type
- switch content type using set-pnplistitem (see https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitem?view=sharepoint-ps)
- FromelardOct 12, 2018Iron Contributor
Dear all,
I finally found how to do the Repost Page Creation with CSOM only.
The missing parts were the page layout to load correctly the page in edit mode, the PromotedState to be sure it will be considered as a news and the last ID to know exactly the target:
- ["_OriginalSourceSiteId"]
- ["_OriginalSourceWebId"]
- ["_OriginalSourceListId"]
- ["_OriginalSourceItemId"]
The code has to be similar to the following one:
$NewPageitem["ContentTypeId"] = "0x0101009D1CB255DA76424F860D91F20E6C4118002A50BFCFB7614729B56886FADA02339B00874A802FBA36B64BAB7A47514EAAB232"; $NewPageitem["PageLayoutType"] = "RepostPage" $NewPageitem["PromotedState"] = "2" $NewPageitem["Title"] = $CSVItem.NewsTitle $NewPageitem["ClientSideApplicationId"] = "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" $NewPageitem["_OriginalSourceSiteId"] = $MyDestinationPageSiteColl.ID $NewPageitem["_OriginalSourceWebId"] = $MyDestinationPageweb.ID $NewPageitem["_OriginalSourceListId"] = $MyDestinationPagelist.ID $NewPageitem["_OriginalSourceItemId"] = $MyDestinationPageFileitem["UniqueId"].ToString() $NewPageitem["_OriginalSourceUrl"] = $MyCSVNewsURL $NewPageitem["Editor"] = $MyEditoruserAccount.Id $NewPageitem["Author"] = $MyEditoruserAccount.Id $NewPageitem["Description"] = $MyCSVNewsDescription $NewPageitem["BannerImageUrl"] = $MyCSVNewsPictureURL; $NewPageitem["Modified"] = $MyCSVPublishingDate; $NewPageitem["Created"] = $MyCSVPublishingDate; $NewPageitem["Created_x0020_By"] = $MyEditoruserAccount.LoginName $NewPageitem["Modified_x0020_By"] = $MyEditoruserAccount.LoginName $NewPageitem["FirstPublishedDate"] = $MyCSVPublishingDate; $NewPageitem.Update(); $MyctxTemp.Load($NewPageitem); $MyctxTemp.ExecuteQuery();
It's now working perfectly and the only point i'm fighting with is the picture display.
Thanks a lot for your help
Fab
- SPDev8Mar 07, 2019Copper ContributorNice example!
We're using a custom content type that inherits from Repost Page and one additional detail that helped us was to set LayoutWebpartsContent to null. The seemingly magical fields (Link, Preview image, Title) and Edit button didn't appear until we cleared the content.
listItem["LayoutWebpartsContent"] = null; // C# CSOM
- FromelardOct 11, 2018Iron Contributor
Interesting idea, I tried to create the item first and change the content type list you are proposing, but it was not working because this Page library is a "document library" and the new-item (in CSOM mode) refuse to create it without a file.
But I will try to apply this idea using the PnP this time.
Thanks for your help.