‘Title’ field and property not available on SPItem when using a View to access the SPListItemCollection

You can get an SPListItemCollection from a List using a View with the following code:

SPList list = SPContext.Current.Web.Lists["My List"];

SPListItemCollection items = list.GetItems(list.Views["All Items"]);

When then try to access the Title field of any of the individual SPListItem instances in the collection you will receive an ArgumentExecption

//all these statements will throw an Argument Exception
string titleField = item[0]["Title"];
string titleProperty = items[0].Title;
string titleValue = items[0].GetFormattedValue("Title");

As a workaround, you can access the Title field value using the LinkTitle field:

//this will return the correct value
string title = items[0].GetFormattedValue("LinkTitle");

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>