Add images to MediaPicker2 property programmatically using Umbraco 7.6.3 and new PropertyConverters
Hi
I need to create multiple images against a property in the content tree node.
Previously you could save images into the image folder and concat the Id's into a string and then pass that string to SetValue for a MediaPicker.
Now we have the new MediaPicker2 and the use of udis how do I programmatically create images for the MediaPicker2??
Previously I did something akin to this:
var gallerySavedPics = "";
if (model.GalleryPics != null && model.GalleryPics.Count > 0)
{
var mediaService = Services.MediaService;
foreach (var pic in model.GalleryPics.Where(p=> p!= null))
{
var media = mediaService.CreateMedia(pic.FileName, 2221, "Image");
mediaService.Save(media);
media.SetValue("umbracoFile", pic);
mediaService.Save(media);
gallerySavedPics += media.Id + ",";
}
if (gallerySavedPics != "")
{
createdForSale.SetValue("classifiedPictures", gallerySavedPics);
}
}
But this wont work now as I know that passing a string of Id's will not work for MediaPicker2
Add images to MediaPicker2 property programmatically using Umbraco 7.6.3 and new PropertyConverters
Hi
I need to create multiple images against a property in the content tree node. Previously you could save images into the image folder and concat the Id's into a string and then pass that string to SetValue for a MediaPicker.
Now we have the new MediaPicker2 and the use of udis how do I programmatically create images for the MediaPicker2??
Previously I did something akin to this:
But this wont work now as I know that passing a string of Id's will not work for MediaPicker2
You need to use a comma-separated list of UIDs, which are basically GUIDs with a prefix. So you would save something like this as your value:
Have a look at this post I made to give you some pointers:
https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/85761-setting-the-value-of-multinodetreepicker2-programatically#comment-273131
is working on a reply...