Open erwinvanhunen opened 6 years ago
From @DorjeM on September 28, 2017 22:4
I've checked using SharePoint designer and when I run code like the following
Set-PnPListItem -List "SitePages" -Id 29 -Values @{"BannerImageUrl" = "";}
The code within the ASPX page is modified to
<mso:BannerImageUrl msdt:dt="string"></mso:BannerImageUrl>
But the page when viewed in the borwser doesn't show no bannerimage.
Same if I copy the <mso:BannerImageUrl value from another page and use set-PnPListItem to insert it into a page ID29 . The ASPX page changes but the page doesn't display the new banner image. e.g.
Set-PnPListItem -List "SitePages" -Id 29 -Values @{"BannerImageUrl" = "https://brighterdays.sharepoint.com/_layouts/15/getpreview.ashx?guidSite=7b7f24b2-a8f8-47b9-ba32-99d7d24ea2bf&guidWeb=a6b51390-845d-4345-95c7-15b16d9048f9&guidFile=0b5854ac-fc5e-41d4-a772-a9fa0eae2b80, https://brighterdays.sharepoint.com/_layouts/15/getpreview.ashx?guidSite=7b7f24b2-a8f8-47b9-ba32-99d7d24ea2bf&guidWeb=a6b51390-845d-4345-95c7-15b16d9048f9&guidFile=0b5854ac-fc5e-41d4-a772-a9fa0eae2b80";}
Hope this helps
From @chrisobriensp on October 4, 2017 10:42
I'm also having issues trying to set the BannerImageUrl. I've tried various things, including:
It seems that the LayoutWebpartsContent property is also relevant here (i.e. things will work if some modification to this is performed). Through some reverse-engineering of this property (including a lot of XML/JSON parsing, I've been able to get things working under certain conditions) - however, we need a reliable, simple abstraction onto this.
PnP team - can you help at all? Even if you can tell us what is needed before your method arrives, that would be great :) @jansenbe @VesaJuvonen
LayoutWebpartsContent contains a key called imageSourceType that should be 2 for custom images, 4 for default image, 0 for no image.
Thanks Rafaelki . can't find the property LayoutWebpartsContent . How to set this property of a modrn page using C#.
Just wondering if we have an update on this issue? I've tried to change the BannerImageUrl both by cmdlets and xml-provisioning but currently I'm stuck.
So you shouldn't manually set banner image url: when you save a page we'll apply similar logic as the out-of-the-box UI, meaning we'll try to find an image and text on the page and use that to configure the bannerimageurl and description properties of the page. Technically speaking you could override the bannerimageurl property after the page has been saved, but would not recommend doing that as a page update might override that again.
@Rafaelki @jansenbe We are blocked by this issue too, our requirements is to create the news article and set the banner image programmatically, but the LayoutWebpartsContent
is always null, could you advise how to proceed or work around?
Hi @alexchx , this code is working for me:
$listName = 'sitepages'
$listItemId = 6
$getPageFields = (get-PnPListItem -List $listName -Id $listItemId).FieldValues
$lwc = $getPageFields.LayoutWebpartsContent
$newLwc = $lwc -replace ""layoutType":"FullWidthImage"", ""layoutType":"NoImage""
$newLwc = $newLwc -replace "imageSource":"(.*?)"", "imageSource":"""
Set-PnPListItem -List $listName -Identity $listItemId -Values @{"LayoutWebpartsContent" = $newLwc}
@Rafaelki Thank you and sorry for the late response, I just noticed that we're using old version of PnP, just upgraded it and all dependencies, now your workaround works well.
By the way, I noticed the banner could be set as below too, but it will cause another trouble that the webparts added by ClientSidePage.AddControl
will be all ignored.
var page = new ClientSidePage(context) { PageTitle = title };
page.PageHeader.ImageServerRelativeUrl = banner;
@jansenbe The provisioning of FieldValues on ClientSidePage to File Propertybag does not work for Complex and Tokenized Values because of this Code Block from Line 533 of ObjectClientSidePages does not use Parser
foreach (var pageProperty in clientSidePage.Properties)
{
if (!string.IsNullOrEmpty(pageProperty.Key))
{
pageFile.Properties[pageProperty.Key] = pageProperty.Value;
}
}
From @DorjeM on September 25, 2017 21:13
I think I’ve discovered a bug/issue with setting the BannerImageUrl for SharePoint online Modern Pages.
I expect that when I run the following the banner for page ID2 will change
Set-PnPListItem -List "SitePages" -Id 2 -Values @{"BannerImageUrl" = " https://contoso.sharepoint.com/sites/mycomsite3/bannerimages/bread-braid-tedster-sml.jpg";}
When I check using the following code the page ID2 reports it’s banner has been changed.
BUT when I actually view the page in the browser the banner of page ID2 has not changed.
My goal is to use PNP cmdlets to set the banner image on new pages, to an image I’ve already uploaded to a library within the site.
Cmdlet versions
Cmdlet install
Please tell me what I'm doing wrong when I set the BannerImageUrl. Your experience and knowledge greatly accepted.
Copied from original issue: SharePoint/PnP-PowerShell#1106