0

Given I have a Guid pointing to an Image. How can I query that image for it's meta data fields (title, description, etc)? Is there helpers for reading the description of an image?

Carl R
  • 8,104
  • 5
  • 48
  • 80

1 Answers1

1

Something like this works.

        string description = null;
        using (DataConnection connection = new DataConnection())
        {
            var mediaFile = connection
                .Get<IMediaFile>()
                .Where(m => m.Id == pictureId)
                .FirstOrDefault();
            if(null != mediaFile)
            {
                description = mediaFile.Description;
            }
        }
Carl R
  • 8,104
  • 5
  • 48
  • 80
  • Yup, that would generally be the way to do it. On bigger sites its important to include the StoreId as well as the Id since you can have media across several stores – Pauli Østerø Aug 03 '17 at 21:14
  • Thanks for the gotcha! :) – Carl R Aug 03 '17 at 21:38
  • @PauliØsterø Using the default News functionality, the Picture has a format "MediaArchive:22af4fb1-eb4b-4447-9a9c-518484a4cbdb". Is StoreId "MediaArchive"? – Carl R Aug 03 '17 at 21:43
  • 1
    That is correct, the StoreId is in the format of a string and the default one in C1 has the id of "MediaArchive". If you don't pass a StoreId, C1 will assume the id of the first store it encounters, which in most cases is the only one and therefor the one you had in mind :) – Pauli Østerø Aug 04 '17 at 00:38