Copied to clipboard

Flag this post as spam?

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


  • Johan Plesner Hamann 105 posts 199 karma points
    May 10, 2014 @ 23:15
    Johan Plesner Hamann
    0

    umbraco 7 media get Alias

    How do I get the media alias in Umbraco 7?

    And where can I see all the names of the properties?

    thanks,
    Johan

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 11, 2014 @ 01:01
    Jan Skovgaard
    0

    Hi Johan

    How are you currently trying to fetch them? Using Razor or XSLT? Should be the same as you would do in earlier versions of Umbraco.

    Are you using the new image cropper? If so then make sure to read the documentation here http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Image-Cropper

    /Jan

  • Johan Plesner Hamann 105 posts 199 karma points
    May 11, 2014 @ 14:19
    Johan Plesner Hamann
    0

    I've created a Media Type called Link, and in razor I would like to check what type I´m dealing with.

  • Johan Plesner Hamann 105 posts 199 karma points
    May 12, 2014 @ 15:00
    Johan Plesner Hamann
    0

    Is there a way to get Media by Type?

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 12, 2014 @ 15:46
    Ali Sheikh Taheri
    0

    Hi Johan,

    Actually there is a way, you can use MediaService as below to get a list of media files by Type.

    you need to pass media type id, as an example I've passed 123.

    var listOfMediaFilesByType = Services.MediaService.GetMediaOfMediaType(123)
    

    I hope that helps.

    Cheers

    Ali

  • Damian Green 452 posts 1433 karma points
    May 12, 2014 @ 16:55
    Damian Green
    0

    You can also get the media type using the media type service if you dont know the id or dont want to hard code it:

    var mType = UmbracoContext.Application.Services.ContentTypeService.GetMediaType("alias");
    
    //check for null etc..
    
    var media = UmbracoContext.Application.Services.MediaService.GetMediaOfMediaType(mType.Id);
    
    foreach (var m in media)
    {
       //each media item
       //
    }
    

    Damian

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    May 12, 2014 @ 17:41
    Ali Sheikh Taheri
    1

    Damian,

    I think your code has gone wrong a little bit MemberTypeService ? Why Member?

  • Damian Green 452 posts 1433 karma points
    May 12, 2014 @ 19:01
    Damian Green
    1

    Doh! I misread MemberType as MediaType. You need to use the ContentTypeService,

    I have updated the post. :)

    Sorry for the confusion.

    Damian

  • Johan Plesner Hamann 105 posts 199 karma points
    May 12, 2014 @ 20:45
    Johan Plesner Hamann
    100

    Hey you guys

    thanks for your great help!

    I've tried your code and it works, just not the way I wanted.

    it's from the wrong side, I would like to take an item and see what type it was.

    so I found out If I wrote this @item.ContentType what I get is Umbraco.Core.Models.PublishedContent.PublishedContentType

    Umbraco.Core.Models.PublishedContent.PublishedContentType h = image.ContentType;
    <p>@h.Alias</p>
    

    found it on this page our.umbraco.org/.../media

    But thanks for the help, I really appreciate it!

    Regards

  • Graham Roberts 13 posts 42 karma points
    Jul 21, 2015 @ 09:37
    Graham Roberts
    0

    Thanks Johan, for posting your solution. This worked for me and helped me a lot.

Please Sign in or register to post replies

Write your reply to:

Draft