Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 936 posts 2571 karma points
    Nov 19, 2014 @ 10:01
    Claushingebjerg
    0

    Getting file type of media

    I have a download section, and i would like to have icons for the different files according to their file type. So i have a pdf icon on the link for a downloadable .pdf, a word icon for an .doc and so on.

    How do i get the file type/suffix for a media file?

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Nov 19, 2014 @ 10:07
    Jan Skovgaard
    100

    Hi Claus

    That can actually be achieved purely by using CSS - See this tutorial for instance http://www.hongkiat.com/blog/css3-attribute-selector/

    This pen might also be useful http://codepen.io/tevko/pen/DdsnK

    Hope this helps.

    /Jan

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 19, 2014 @ 10:21
    Dennis Aaen
    2

    Hi Claus,

    If you want to get the file type of media in razor code you could do it like this:

    In the example I am using the media picker.

    @{
        var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("mainImage"));
        @mediaItem.GetPropertyValue("umbracoExtension")
    }

    Hope this helps,

    /Dennis

  • Claushingebjerg 936 posts 2571 karma points
    Nov 19, 2014 @ 11:08
    Claushingebjerg
    0

    Thanks both of you. H5YR

    I'll mark Jans as the solution as its the most flexible in my case.

  • Enkosi 11 posts 86 karma points
    Jan 20, 2022 @ 09:52
    Enkosi
    0

    If you want to get the file type in a UmbracoApiController you can do the following:

    int mediaId = 1095;
    var fileItem = Umbraco.Media(mediaId);
    var fileType = (string)fileItem.GetProperty("UmbracoExtension").GetValue();
    

    That is assuming you already have the file Id of the document you are interested in.

Please Sign in or register to post replies

Write your reply to:

Draft