Retrieve custom field from image

Posted by Community Admin on 03-Aug-2018 17:37

Retrieve custom field from image

All Replies

Posted by Community Admin on 15-Mar-2011 00:00

Hello all,

I have created a custom field for my images called "image order" that will be used to do an independent ordering of images in a custom control.  My question is: how can I get that value out of the database?  I have a general setup that works (using the fluent API) but it doesn't return the custom fields.  Below is the code that will retrieve the images out of the Album that I want (minus the custom fields).

var list =
    App.WorkWith().Albums().Where(a => a.Title == "Promos").Get().FirstOrDefault().Images.Where(
        i => i.Status == ContentLifecycleStatus.Live);

Can someone please direct me to the solution?

Thank you,
Tim

Posted by Community Admin on 15-Mar-2011 00:00

Hello Bryan,

Telerik.Sitefinity.Libraries.Model.Image has extension method GetValue which you can use to get the value of the custom field you have created. You should add reference to Telerik.Sitefinity.Model.DataExtensions to use GetValue.

Regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 15-Mar-2011 00:00

Thank you very much for the quick reply.  In reading a couple of the other posts about Custom Fields, I could see that using GetValue would be the way to go, but when I try to import the Telerik.Sitefinity.Model.DataExtensions namespace I am getting an error.

In my project I have a reference to Telerik.Sitefinity.Model as well as several other Sitefinity specific dll's (all taken from my installation of the Sitefinity CMS libraries folder).  It is strange that I am not able to access that namespace at all.

Any suggestions?

Thank you,

Tim
------------------------------------------------------------
EDIT:
I figured out this issue I was having (sort of) and this is how I access the custom field now:

var imageOrder = Telerik.Sitefinity.Model.DataExtensions.GetValue(image, "ImageOrder");
This works fine and now I can sort the images by my custom field.

Thank you for all your help today. I appreciate it.

Tim
-----------------------------------------------------------

This thread is closed