Copied to clipboard

Flag this post as spam?

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


  • Paul Sørensen 302 posts 648 karma points
    Mar 15, 2013 @ 21:28
    Paul Sørensen
    0

    Get media node by id using MediaService

    Hi

    I'm trying to get the Media node by Id using th MediaService. I would suppose it would something like this but it doen't work

                    var ms = Umbraco.Core.Services.MediaService;
                    var m = ms.GetById(i);
                    if (m != null)
                    {
                        var file = m.GetValue("umbracoFile");
                        url = (string)file;
                        return url;
                    }
                    return @"\";

    How can I do that?

    /Paul S

    ddd

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 16, 2013 @ 07:34
    Fuji Kusaka
    0

    Hi Paul,

    Not sure what you are trying to achieve here. Anyways if you are using a Media Picker this should work

    var m = @Model;

    if(!String.IsNullOrEmpty(m.docType)){
               var f = Model.MediaById(@m.docType);
        @f.Name // media node Name
    @f.id // media node Id
    }
  • Paul Sørensen 302 posts 648 karma points
    Mar 16, 2013 @ 08:36
    Paul Sørensen
    0

    Hi

    Eventually I would like to get the URL for the Image, but I cn't use Razor becuse it's backend code

    /Paul S

  • 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