Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4503 posts 10046 karma points MVP 2x admin c-trib
    Dec 10, 2014 @ 18:44
    Ismail Mayat
    0

    SetValue with Multiple Media picker

    Hello,

    I have a doctype that has multiple media picker, I am creating content of this type using content service and then looking to set the multiple media picker field code looks like

    portfolio.SetValue(Helpers.DocTypeConstants.Portfolio.Images,packageItem.MediaIds);

    where MediaIds is List of ints, my question is will that work or do i need to give the value as csv string list or??

    Regards

    Ismail

  • Jeavon Leopold 3005 posts 13193 karma points MVP 7x admin c-trib
    Dec 10, 2014 @ 19:50
    Jeavon Leopold
    100

    Hi Ismail,

    You will have to convert to CSV, something like this:

    portfolio.SetValue(Helpers.DocTypeConstants.Portfolio.Images,String.Join(",", packageItem.MediaIds.Select(x => x.ToString()).ToArray()));
    

    Jeavon

  • David Armitage 333 posts 1318 karma points
    Jun 21, 2020 @ 04:42
    David Armitage
    0

    If anyone is having trouble with Umbraco 8 then this is how I do it.

    You basically need to get the UDI of the media item and use this to pass into the media picker field.

    if you are dealing with a multiple media picker from memory I believe it is a comma separated list of Udis.

    var content = _contentService.GetById("content-node-id-here");
    if (content != null)
    {
        content.SetValue("basicStringValue", "some-string-content");
        content.SetValue("anotherBasicStringValue", "some-string-content");
    
        IMedia media = _mediaService.GetById(mediaId);
        if(media != null)
        {
            content.SetValue("logo", media.GetUdi());
        }
    
        if(image != null)
             _contentService.SaveAndPublish(content);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft