+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Retrieve custom field from image

Retrieve custom field from image

3 posts, 1 answered
  1. Rushman
    Rushman avatar
    16 posts
    Registered:
    31 Dec 2008
    15 Mar 2011
    Link to this post
    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
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    15 Mar 2011
    Link to this post
    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
    Answered
  3. Rushman
    Rushman avatar
    16 posts
    Registered:
    31 Dec 2008
    15 Mar 2011
    Link to this post
    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
    -----------------------------------------------------------
3 posts, 1 answered