Reputation: 21
I am using CSOM API to update fields in a SharePoint list. I can update all fields fine, I just can't update or add to the "Image" Field. This is a new field type added in late 2020, separate from the "Hyperlink/Picture" field type. I see in the List settings, it is marked as "Thumbnail".
I have tried to set the image column to a url, as you can do this for the previous "Hyperlink/Picture" field type. Is there a way to update this field using CSOM? I can't find any mention of this new Image field type in any of the documentation.
ListItemCreationInformation itmCreation = new ListItemCreationInformation();
newItem = myList.AddItem(itmCreation);
string imageUrl = "www.myImage.com"
newItem["IMAGECOLUMN"] = imageUrl ;
newItem.Update();
cc.ExecuteQuery();
Upvotes: 1
Views: 628
Reputation: 21
The modern "Image" Field is expecting a JSON formatted object. I created an Image class, serialized it and then sent it that way:
Entities.Image imgg = new Entities.Image
{
fileName = "img.jpg",
serverUrl = "https://site.sharepoint.com",
serverRelativeUrl = "/sites/mySite/Shared%20Documents/New Images Upload/img.jpg"
};
string json = JsonConvert.SerializeObject(imgg, Formatting.Indented);
ListItemCreationInformation itmCreation = new ListItemCreationInformation();
newItem = myList.AddItem(itmCreation);
newItem["imageColumninternalName"] = json;
newItem.Update();
cc.ExecuteQuery();
And it worked, strange I couldn't find any documentation on this.
Upvotes: 1