Skip to content

Inline Images in Text parts on SharePoint Online Modern page not working #1558

@raviteja333

Description

@raviteja333

Category

  • Bug

Describe the bug

We are programmatically creating modern pages on a SharePoint online communication site using PnP Core SDK. As part of that, we are injecting html code into a text part. Our HTML is a combination of text and images. When the page is created, everything looks fine, and we can see all text and images fine. However, when we edit the page, images are disappearing, and we can't get them back.

Very similar to the issue reported here #759

We are using below code to create html blob to insert image into the text part as suggested in this https://pnp.github.io/pnpcore/using-the-sdk/pages-webparts.html#using-inline-images-in-text-parts

// Create the page
var page = await context.Web.NewPageAsync();

// adding sections to the page
page.AddSection(CanvasSectionTemplate.OneColumn, 1);

// Create text part
var textPart = page.NewTextPart();

// Prepare inline image for inserting
var inlineImage = await page.GetInlineImageAsync(textPart, "/sites/prov-2/siteassets/__siteicon__.png", new PageImageOptions() 
{ 
    Alignment = PageImageAlignment.Left,
    Width = 200,
    Height = 200
});

// Insert the inline image in the text part text
textPart.Text = $"<H1>My header</H1>{inlineImage}<p>Text after image</p>";

// Adding text part control to the first section, first column
page.AddControl(textPart, page.Sections[0].Columns[0]);

// Save the page
await page.SaveAsync("MyPage.aspx");

Expected behavior

We are expecting the images to sta1 even after editing and saving the page back. But, they are disappearing now. It was working until few days ago. But, suddenly stopped working for new pages we are creating as well as the old pages we created so far. It seems like an update from SharePoint broke.

Environment details (development & target environment)

  • SDK version: Nuget PnP.Core -Version 1.14.0
  • OS: Windows 10
  • SDK used in: Asp .Net Windows Forms App
  • Framework: .NET 8
  • Browser(s): SharePoint Online using Edge Version 129.0.2792.89
  • Tooling: Visual Studio 2022
  • Additional details: It was working until few days ago. But, suddenly stopped working for new pages we are creating as well as the old pages we created so far. It seems like an update from SharePoint broke.

Thanks for your contribution! Sharing is caring.

Metadata

Metadata

Assignees

Labels

area: pages API 📄Working with modern pagesbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions