无法更新SharePoint发布页面图像

时间:2015-10-15 06:50:38

标签: c# sharepoint-2013 csom

我正在尝试更新发布页面图像网址但不知何故执行查询命令后。其值保存为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 ();

1 个答案:

答案 0 :(得分:2)

发布图像字段值应按以下格式指定:<img src='{imageurl}'>

示例

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();
}