Question

I m using simple code to assign HTML content to PublishingPageContent field of my ASPX page in SharePoint Online:

pageItem.PublishingPageContent = "<img src=\"smiley.gif\">";

However, the resulting page is empty. Why it happens? How to put an image into page body through code? Thank you.

Was it helpful?

Solution

Try using the below code in a simple console application first. Helps in isolating the issue :

List list = context.Web.Lists.GetByTitle("Pages");
context.Load(list);

var item = list.GetItemById(8);
context.Load(item);
context.ExecuteQuery();

item["PublishingPageContent"] = "<img src =\"/sites/test/PublishingImages/smiley.gif\" />";

item.Update();
context.ExecuteQuery();

Have modified it to use server-relative url of the image. Modify it as per your image location in SharePoint.

Also, have closed the image tag, but i dont think it going to affect end-result since its self-closing.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top