Programmatically set the value of a MultipleMediaPicker field
I have a custom document type with a MultipleMediaPicker field/control, and I just want to assign a media object to it, basically set its value to an existing media object.
Here is the document type:
Here is my code:
var images = ApplicationContext.Current.Services.MediaService.GetDescendants(1360);
var person = ApplicationContext.Current.Services.ContentService.GetChildrenByName(1358, "23329741").FirstOrDefault();
var h = person.GetValue<int>("userId");
var oop = images.FirstOrDefault(x => x.Name.StartsWith(h.ToString()));
person.SetValue("userPhoto", oop.GetValue(umbracoFile));
The code executes without any issues, the oop variable is a media object and I checked that it does indeed contain the image in question, but no matter how i try to set the userPhoto field it remains empty with no image. I don't know value userPhoto expects, is it an ID of the media object? An umbracoFile? I couldn't find the answer anywhere.
Programmatically set the value of a MultipleMediaPicker field
I have a custom document type with a MultipleMediaPicker field/control, and I just want to assign a media object to it, basically set its value to an existing media object. Here is the document type:
Here is my code:
The code executes without any issues, the oop variable is a media object and I checked that it does indeed contain the image in question, but no matter how i try to set the userPhoto field it remains empty with no image. I don't know value userPhoto expects, is it an ID of the media object? An umbracoFile? I couldn't find the answer anywhere.
Hi!
A media picker are only storing the ID of the media item, you could try something like this:
Are you calling the save-method of the content service as well?
Cheers!
Thank you Markus! I've been breaking by head over this simple thing for a while now, much appreciated!
Cheers!
is working on a reply...