views:

402

answers:

1

Hi I have a question about SPListItem and how to retrieve values from it. In the view I am in I can access the "Article" no problem but when I try to access the "Link" I can an error saying object not initalized. I don't understand whats going on? Why can I not get the Link when I can get the Article field. Here is the code I am using:

SPList myList = eachWeb.Lists["Listings"];
SPListItemCollection myItemCollection = myList.GetItems(myList.Views["Active Announcements"]);
for (int i = 0; i < myItemCollection.Count; i++)
{
SPListItem realitem = myItemCollection[i]; 
writer.Write(realitem["Article"].ToString()+"<BR>"); // Works without the bottom line
writer.Write(realitem["Link"].ToString()+"<BR>");  // Causes error

My view contains a column for both Article and Link. Thank you.

+3  A: 

The internal name of a field may not match the display name; especially if you've changed the name after creating the list. Try debugging and taking a look at the names of the fields in the SPListItemCollection and see if you can figure out which one it is there.

Andy Mikula
How can I call by the internal IE)what is realitem["Article"] calling? is it the internal or display name?
Oliver S
You're always using the internal name to get the item, and in some cases the real name will match the display name. This is not always the case - for example, I have a field in my list that displays 'Title' when I view the list, but its internal name is 'Name'.
Andy Mikula
Jason