Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    Nov 22, 2011 @ 04:06
    Ayo Adesina
    1

    Node.GetProperty Returning a number I want the image URL form Media picker

    Hello guys I have an umbraco document type and one of the properties is a Media Picker

    I have a usercontrol and I am trying to get the URL of the image that was selected for that property.

    var x = imageNode.GetProperty("image").Value;
    This is returning a number, which I think is an Id of some kind, but I want the URL of the image.

    Any ideas...please?

     

     

  • Evan Jardine 108 posts 168 karma points
    Nov 22, 2011 @ 05:31
    Evan Jardine
    0

    If you are using razor you can do something like this;

    @{
    var m = @Library.MediaById(@Model.image);
    var imageurl = m.umbracoFile;
    }
     <img src="@imageurl" ....

    Cheers

    Evan

  • SideSam 13 posts 33 karma points
    Nov 23, 2011 @ 13:33
    SideSam
    0

    Here is what I am using to retrieve image URL from media id

    public string GetImageUrlFromNodeId(int mediaId)
    {
    Media mediaFile = new Media(mediaId);
    return mediaFile.getProperty("umbracoFile").Value.ToString();
    }
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 23, 2011 @ 13:50
    Jeroen Breuer
    0

    Hi SideSam,

    You shouldn't use that code. It uses the Media API which is very slow and should only be used to modify media. Evan his example is good.

    This wiki is about the Document API, but it's the same for Media: http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-a-node-and-a-document.

    Jeroen

  • Ayo Adesina 445 posts 1059 karma points
    Nov 24, 2011 @ 22:15
    Ayo Adesina
    0

    I am not using razor its in a user control, Jeroen good you past a code snippit please?

  • Evan Jardine 108 posts 168 karma points
    Nov 24, 2011 @ 22:37
    Evan Jardine
    0

    In a usercontrol you need to look at the Document API.

    http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties

    var x = imageNode.GetProperty("image").Value;

    Document doc = new Document(x);

    var imageUrl = doc.getProperty("umbracoFile").Value.ToString();
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 25, 2011 @ 11:24
    Jeroen Breuer
    0

    Hi Evan,

    As I said before you shouldn't use the Document API in a usercontrol which is used in your website. If your usercontrol is used as a datatype you can use the Document API, but otherwise you need to use the Node API which is 10x faster. 

    Again read this wiki: http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-node-and-document and also this blog with more info: http://www.netaddicts.be/articles/document-api-vs-nodefactory.aspx.

    In a usercontrol you can also use Razor code. Something like this should work:

    dynamic node = new DynamicNode(Node.GetCurrent());
    var imageUrl = node.MediaById(node.image).umbracoFile;

    I didn't test that code, but something like that should work.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft