Copied to clipboard

Flag this post as spam?

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


  • Jason Mackay 98 posts 149 karma points
    Feb 20, 2014 @ 10:42
    Jason Mackay
    0

    Get Media Type

    Hi all, not sure if this is a Umbraco 7 query or a Razor query but I need the Media Type of a certain media from the Multiple Media Picker. It would need to be specific, ie a PDF, a DOC file. Not just File, Folder, Image. Is this possible?

    If not is there a way, to get the file extension from the URL using Razor?

    My code so far:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @if (Model.Content.HasValue("resouces"))
    {
        var docList = Model.Content.GetPropertyValue<string>("resouces").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var docCollection = Umbraco.TypedMedia(docList).Where(x => x != null);
    
        foreach (var docItem in docCollection)
        {      
            //Need if statement for media type
            <img src="@docItem.Url" />      
        }                                                               
    

    }

     

    Any help would be great, thank in advance.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 20, 2014 @ 11:41
    Dennis Aaen
    100

    Hi Jason,

    One way you can get the file extension, of a media item is by using this:

    @docItem.GetProperty("umbracoExtension").Value

    I hope this can help you further.

    /Dennis

  • Jason Mackay 98 posts 149 karma points
    Feb 20, 2014 @ 11:57
    Jason Mackay
    0

    Excellent Dennis, exactly what I was after.

    Cheers

    Jason

Please Sign in or register to post replies

Write your reply to:

Draft