Problem Accessing Custom Field Value
I am using an image album to store photos and bio information for some of the professionals in my company. My goal is to write a user control to display these and offer some advanced functionality that I can't get out of just displaying them in a modified image library in SF. I am binding to a repeater right now as I get familiar with utilizing Fluent. Everything works perfect until I try to access the data values in custom fields I have set up. Below is the code I am using...
Me.rptrTest.DataSource = App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status =
ContentLifecycleStatus.Live And w.Album.Title.Value = "Investment Management Professionals" And
w.GetValue("ProfessionalName").ToString.StartsWith("K"))
rptrTest.DataBind()
Hi Craig,
1. Could you tell us where "Object Reference Not Set To An Instance of an Object." is thrown. This is a very common error which says that the object "x" is null
2. If you call Get() before you try to get the item by custom field are there any results?
I suppose that
App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status =
ContentLifecycleStatus.Live And w.Album.Title.Value = "Investment Management Professionals"
does not return an item and when you call w.GetValue("ProfessionalName")
there is no object "w" that you can query.
Greetings,
Ivan Dimitrov
the Telerik team
Hi Ivan,
It is thrown on that very line. I do get the results I expect if I shave the line back to either of the following and omit "And
w.GetValue("ProfessionalName").ToString.StartsWith("K"))"
:
App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status = ContentLifecycleStatus.Live '//returns all live images as expected
App.WorkWith().Images().Get().ToList().Where(Function(w) w.Status = ContentLifecycleStatus.Live And w.Album.Title.Value = "Investment Management Professionals" '//returns all live images in my Investment Management Professionals album as expected
Here is a screenshot...
I've attached a screenshot showing my custom fields. If I plug any of those field names in to the .GetValue(x), I get the error. If I plug any of the default fields in as shown in the bottom of the screenshot, it works just fine.
Hello Craig ,
I am not able to replicate this issue locally unless this is an issue with the way that the fluent api works in VB( we have some issues with VB way).
I attached a short video with my test.
Greetings,
Ivan Dimitrov
the Telerik team
Ivan,
I've redone everything in C# (see code below) and get a "System.NullReferenceException: Object reference not set to an instance of an object".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity;
public partial class custom_Professionals : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
var imgs = App.WorkWith().Images().Where(i => i.Status == ContentLifecycleStatus.Live && i.GetValue<
string
>("ProfessionalNickName").StartsWith("K")).Get().ToList();
rptrTest.DataSource = imgs;
rptrTest.DataBind();
Hello Craig ,
I am sorry, but I am not able to replicate this issue. If you use an older version, please upgrade to the latest one. You can also give a try with a new project to see whether the same issue will occur. You can install it through the project manager for a seconds. You can also open a support request and send some sample project where we can see how you add the custom field.
Greetings,
Ivan Dimitrov
the Telerik team
Hi,
I was also having the same problem, I got a solution for this in another forum post Link to post
The solution is, we can get the value like in given manner:
var imageOrder = Telerik.Sitefinity.Model.DataExtensions.GetValue(image, "ImageOrder");
Thanks
Hi Amit,
Thank you for sharing this with the community.
Regards,
Strahil Strahilov
Telerik