Forum Discussion
C# ClientContext - Removing Image from Page Banner on Modern Page - SP 2019
I am trying to create a ClientSidePage in C#. I have been able to make the page, but I can't figure out how to remove the image from the Page Banner. The option exists to remove the image and keep the banner when in the UI's edit mode.
- I know about the ClientSidePage.LayoutType to "Home", but that removes the entire banner, including the title.
- I have tried the following:
clientSidePage.PageHeader.LayoutType = ClientSidePageHeaderLayoutType.NoImage;
... but that has no effect.
How do I remove the image from the page banner without removing the entire banner?
Thanks in advance,
AS
- Nielsvanbeek1985Copper Contributor
AS911 I have the same issue. Original page has no banner and image, after applying the template the page has a banner and no image.
- Carlos_MarinsIron Contributor
Hey guys,
Just to say that with the PnP Powershell I was able to update the page header, setting it to NoImage. You can create the page and then use the following code:
$page.PageHeader.LayoutType = 1$page.Save()I haven't tried it in C#, but since the PnP PowerShelluses CSOM I am sure it is possible. Let me know if you have questions on how to achieve it.Regards,- AS911Copper Contributor
Carlos_Marins Thanks for getting back.
Setting it to "1" (casted to the ClientSidePageHeaderLayoutType, since that is the type that CSOM is looking for) still has no effect, unfortunately.
We are currently opting to make the change through JS instead. I'll try to give an update where that leads.
- Carlos_MarinsIron Contributor
Hi AS911,
Are you using the CSOM library? Which version? Using the latest PnP PowerShell I was able to save a page with the Header set to NoImage.
I am also looking for a way to have a parameter -HeaderLayoutType(something like that) included in the Add-PnPClientSidePage so this problem is solved.
- VamshiGovinduCopper Contributor$page = Get-PnPClientSidePage -Identity Home.aspx
$lwc = $page.PageListItem.FieldValues.LayoutWebpartsContent
$newLwc = $lwc -replace ""imageSourceType":4,"", ""imageSourceType":0,""
Set-PnPListItem -List "SitePages" -Id $page.PageId -Values @{"LayoutWebpartsContent" = $newLwc} -SystemUpdate
This code here should remove the image from the page. ImageSourceType = 4 is default, ImageSourceType = 0 is none, ImageSourceType = 2 is custom image.