Copied to clipboard

Flag this post as spam?

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

  • Claushingebjerg 937 posts 2572 karma points
    Nov 19, 2014 @ 10:01

    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

    Hi Claus

    That can actually be achieved purely by using CSS - See this tutorial for instance

    This pen might also be useful

    Hope this helps.


  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 19, 2014 @ 10:21
    Dennis Aaen

    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"));

    Hope this helps,


  • Claushingebjerg 937 posts 2572 karma points
    Nov 19, 2014 @ 11:08

    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

    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: