Is it possible to programmatically add several Med...
# help-with-umbraco
s
It's easy enough to do content.SetValue("mediapicker", media.GetUdi()) but how do you do it for multiple images?
j
The easiest approach I've found is to create a page with a media picker, select multiple images and then save and see how that data is stored in the database (the umbracoPropertyData table). I think in this case it is just a comma seperated list of udi's, so that would be the data format you'd need to match in your value passed to SetValue
a
The media picker doesn't just save the UDI(s) of the selected media, but a JSON array where each item should have it's own GUID key and a reference to the selected media.
You can use these two classes for inspiration: https://github.com/limbo-works/Limbo.Umbraco.Migrations/blob/v1/main/src/Limbo.Umbraco.Migrations/Models/MediaPicker/MediaPickerList.cs https://github.com/limbo-works/Limbo.Umbraco.Migrations/blob/v1/main/src/Limbo.Umbraco.Migrations/Models/MediaPicker/MediaPickerItem.cs When serialized to JSON (at least when using JSON.net and
Formatting.None
), the serialized string will match the value saved by Umbraco.
s
I often take some initial inspiration of how it "should" look like, especially with references to other items, by adding multiple items to an existing page and checking the examine index
28 Views