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
//
}
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
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
I've created a Media Type called Link, and in razor I would like to check what type I´m dealing with.
Is there a way to get Media by Type?
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.
I hope that helps.
Cheers
Ali
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:
Damian
Damian,
I think your code has gone wrong a little bit
MemberTypeService
? Why Member?Doh! I misread MemberType as MediaType. You need to use the ContentTypeService,
I have updated the post. :)
Sorry for the confusion.
Damian
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 isUmbraco.Core.Models.PublishedContent.PublishedContentType
found it on this page our.umbraco.org/.../media
But thanks for the help, I really appreciate it!
Regards
Thanks Johan, for posting your solution. This worked for me and helped me a lot.
is working on a reply...