Forum Discussion
Modern WebPage - Error with getpreview.ashx when a Repost page is published
When you create a page using the UI SharePoint will pick the first (preview) image it finds and uses that as the image to display the page in the news web part. If you programmatically create pages using the PnP client-side API (so using the .Net PnP Site Core library or using PnP Powershell) then you'll have a similar behavior as the API will try to pick the first image (via entries in the imageSources JSON node), although it's not as enhanced as the native feature.
If you want to change things you could look into setting the BannerImageUrl field. We use the following construct in our API implementation:
item[ClientSidePage.BannerImageUrl] = $"{rootUri}_layouts/15/getpreview.ashx?guidSite={site guid}&guidWeb={web guid}&guidFile={image guid}";
The issue is not into the Banner part, because the value is correctly loaded.
It's only the preview api which is refusing to show it in some mode.
I tried in another call model and it's OK:
From this URL:
- https://[mytenant].sharepoint.com/[mysubsite]/_layouts/15/getpreview.ashx?resolution=3&path=%2Fmysubsite%2Ffunctions%2Fcom%2Fpublishingimages%2Flatest%20emailing.business.jpg&clientType=modernWebPart
To this URL:
- https://[mytenant].sharepoint.com/[mysubsite]/_layouts/15/getpreview.ashx?clientType=docLibGrid&guidFile={5B19514D-5080-43C8-AF7A-092AF52ACF7C}&guidSite={1e4c2649-d8d9-4227-8716-3a6aa65121f3}&guidWeb={d749484e-d2dc-483d-9812-56c8390d44c8}&resolution=Width1024
Fab