Reputation: 13
I'm attempting to retrieve the value of a listitem but keep getting a ArgumentException - Value does not fall within the expected range.
My code is as follows:
if (resultList.Count > 0)
{
SPListItem result = resultList[0];
if (result[Column] != null)
{
return result[Column].ToString();
}
}
In the immediate window I can verify the column does exist and the value can be found in the object tree structure.
result.Fields.GetField(Column).Id
returns a Guid but using it to retrieve the value of the Field results in another ArgumentException:
result[result.Fields.GetField(Column).Id]
Upvotes: 0
Views: 3503
Reputation: 2458
This could happen if you get your list item collection from view (list.GetItems(view)) or from query with ViewFields property set, in this case only the fields included in ViewFields are returned.
Upvotes: 2
Reputation: 567
You need to use InternalName of the field to get its value from SPListItem
result[result.Fields.GetField(Column).InternalName]
Upvotes: 1