Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore fast way to check the mediaItem in the Media Library is an Image or a picture

For the item in Sitecore 'Media Library':

MediaItem mediaItem = Sitecore.Context.Database.GetItem("{E47591D0-48D2-4543-80E4-3836B02AA1A8}");  

The above item is a picture "Tulips.jpg".

How can I check, from code behind, that the above item is actually a Picture/Image?

like image 558
Kamran Avatar asked Nov 27 '25 15:11

Kamran


1 Answers

Once you have your MediaItem object, you can do this:

MediaItem mediaItem = ...

bool isPicture = mediaItem.MimeType.StartsWith("image/");

This works because MIME types of images are formed like this: image/.... For example:

  • image/bmp
  • image/gif
  • image/jpeg
like image 178
Dmytro Shevchenko Avatar answered Nov 30 '25 04:11

Dmytro Shevchenko