Muhammad zaighum
Muhammad zaighum

Reputation: 135

Cannot Update SharePoint Publishing Page Image

I am trying to update publishing Page image url but somehow after execute query command. its value saved as null

        ClientContext targetContext = new ClientContext ("REAL URL");
        Microsoft.SharePoint.Client.File targetFile = targetContext.Web.GetFileByServerRelativeUrl ("REAL URL");
        var targetPublishingPage = PublishingPage.GetPublishingPage (targetContext, targetFile.ListItemAllFields);
        targetContext.Load (targetPublishingPage.ListItem);
        targetContext.ExecuteQuery ();
        targetFile.CheckOut ();
        targetPublishingPage.ListItem["PublishingPageImage"] = "REAL URL";
        targetPublishingPage.ListItem.Update ();
        targetContext.ExecuteQuery ();

Upvotes: 0

Views: 1360

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59358

Publishing Image field value is expected to be specified in the folliowing format: <img src='{imageurl}'>

Example

using (var ctx = new ClientContext(webUri))
{
    var pageFile = ctx.Web.GetFileByServerRelativeUrl(pageUrl);
    var pageItem = pageFile.ListItemAllFields;
    pageItem["PublishingPageImage"] = "<img src='/PublishingImages/PageLogo.png'>";
    pageItem.Update();
    ctx.ExecuteQuery();
}

Upvotes: 2

Related Questions