0

I need to know if a uploaded media item is versionable uploaded or not? But I can't find a property on the Imagefield or MediaItem itself where I can see if the media item was uploaded versionable.

 var imageField = (ImageField)item.Fields[imageFieldId];
 imageField.MediaItem. ?
  • Maybe this will work: var imageField = (ImageField)item.Fields[imageFieldId]; var isMediaItemShared = MainUtil.GetBool(imageField.MediaItem.Fields["Blob"].InnerItem["Shared"], false); – Marek Musielak Sep 11 at 14:05
  • @MarekMusielak No its not returning the right value if shared – squadwuschel Sep 11 at 14:32
  • 1
    I've tested it and it does work for me. I uploaded one image as versioned and another as not versioned and it does show correct values for both. – Marek Musielak Sep 11 at 14:55
  • Meh. versioned = imageField.MediaItem.Template.Parent.Name.Equals("Versioned"); And I don't care if it's illogical; Sitecore has all fields marked "Shared" in the Unversioned folder - as opposed to... Unversioned ;-) – Mark Cassidy Sep 11 at 21:18
3

Does not look like an elegant solution but this might work. There are Versioned and Unversioned template folders under /sitecore/templates/System/Media path. You may try to look if your media item template belongs to one of these folders, smth like this:

if (imageField.MediaItem.Template.InnerItem.Paths.FullPath.StartsWith(
    "/sitecore/templates/System/Media/Versioned"))
{
    // versioned
}
...
  • That was going to be my recommendation - although I would say use the Template ID's vs the path. – Richard Seal Sep 11 at 14:50
  • 1
    Might be a bit tricky since each folder contains 12 templates OOTB... But in case one does not need to deal with 'Flash', 'MP3' and other strange stuff, template IDs can be preferable. – Serhii Shushliapin Sep 11 at 14:56
  • 1
    Stop it with the ID over path nonsense :joy: – Mark Cassidy Sep 11 at 21:16
  • You can check if the template inherits from /sitecore/templates/System/Media/Versioned/File, all the versioned templates inherit from this one. – jammykam Sep 11 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.