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

Forums / Sitefinity SDK / Fluent API to capture custom Field

Fluent API to capture custom Field

4 posts, 0 answered
  1. Jerami Tainter
    Jerami Tainter avatar
    27 posts
    Registered:
    29 Oct 2009
    25 Apr 2011
    Link to this post
    In my blog post section I've created a custom field called preview image. I see its stored in the database and has the appropriate values. Now im trying to render that field into my markup. When I make a call through the Fluent API to retrieve a list of Blog Posts Im not sure how I can capture that custom field. I've tried dataItem.GetValue<string>("preview_image") but that throws an error. 

    Here is how Im capturing all the data:

    var articles = App.WorkWith().BlogPosts().Get().Where(ab => ab.Parent.Title == ARTICLESBLOGNAME && ab.Status == ContentLifecycleStatus.Live).OrderByDescending(ab=>ab.PublicationDate);

    I then bind this to a ListView and it displays all the data like Summary, Title and such as you would expect...I think set up a OnItemDataBound event:

    protected void ArticlesItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if(e.Item.ItemType == ListViewItemType.DataItem)
            {
                var dataItem = (BlogPost)((ListViewDataItem) e.Item).DataItem;
     
                var link = (HyperLink)e.Item.FindControl("NavHyperLink");
                link.NavigateUrl = string.Format("/articles{0}", dataItem.Urls.FirstOrDefault().Url);
     
                var previewImage = (Image)e.Item.FindControl("PreviewImage");
                var imageUrl = dataItem.GetValue<string>("preview_image");
     
                if (string.IsNullOrEmpty(imageUrl)) return;
     
                previewImage.ImageUrl = string.Format("/img/featured/{0}", imageUrl);
     
                 
            }
        }

    I know DataItem is not null because it sets the appropriate navigate url...but when I try and get the custom field it throws out a Object not set error.

    Any ideas?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Apr 2011
    Link to this post
    Hello Jerami,

    Try calling DoesFieldExist method - Extension method that determines if the dynamic field exists on the type. From what you described it looks like your custom field does not exist for the content item.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. Jerami
    Jerami avatar
    12 posts
    Registered:
    31 Mar 2011
    26 Apr 2011
    Link to this post
    Yeah I looked at the database and was attempting to capture the field by its field_name rather then what I specified in the administrative section.

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Apr 2011
    Link to this post
    Hello Jerami,

    I am closing the thread, since the issue looks like resolved.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

4 posts, 0 answered