Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Neil Hodges 320 posts 926 karma points
    Aug 25, 2017 @ 14:28
    Neil Hodges
    0

    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

  • Dan Diplo 1505 posts 5911 karma points MVP 4x c-trib
    Aug 25, 2017 @ 15:41
    Dan Diplo
    1

    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:

    umb://document/a2493a1ab5a2459dbe4d7fddbd7764fd,umb://document/e84a976068654503a90d2eed44ac266f,umb://document/46c0a1a3b5c849ebbc74248376f27a80
    

    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies