Tutorial :SharePoint List Item Not Returning Fields



Question:

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.


Solution:1

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »