Copied to clipboard

Flag this post as spam?

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


  • Tom C 87 posts 222 karma points
    Oct 23, 2014 @ 12:49
    Tom C
    0

    umbracoFile media property in Umbraco 7

    Having just about upgraded from v6 to v7.1.8, I have a bit of code not working,

     

    umbraco.MacroEngines.DynamicNode  media = new umbraco.MacroEngines.DynamicNode(imgId);

    string imageURL = media.GetProperty("umbracoFile").Value.ToString();

     

    before this would return the location of the file on the filesysterm, however now the GetProperty("umbracoFile") is null

    Has this property been removed? if so, how does one now get the file server location for a media item? Or maybe it is just a case of after update it is not in the cache, but there is no way to publish meida items like for other content?

    Thanks

    Tom

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 23, 2014 @ 12:54
    Dennis Aaen
    0

    Hi Tom

    If you are using the media picker, you should be able to do something like this:

    @{
        if(Model.Content.HasValue("imgId")){
            var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("imgId"));
            <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")"/>   
        }  
    }

    In the example above the media picker has a propertyAlias called imgId, and the piece of code check if there are set an image in the page that you are viwing in the browser.

    You can find the documentation here jf you just select single images, and see the strongly typed version: http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker

    If you want to select multiple image take a look here: http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Media-Picker

    Hope this helps,

    /Dennis

  • Tom C 87 posts 222 karma points
    Oct 23, 2014 @ 13:45
    Tom C
    0

    Thanks for your reply Dennis .. I have just managed to fix it now after rebuilding the indexes on the Examine Management tab of the Developer section and it works again, so I think it was just an issue of the upgrade process, but maybe this will help someone else one time.

Please Sign in or register to post replies

Write your reply to:

Draft