0
votes

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]
2
I've found the cause of the exception: I've used List.GetItems(string) instead of the SPQuery overloadWindy

2 Answers

2
votes

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.

1
votes

You need to use InternalName of the field to get its value from SPListItem

result[result.Fields.GetField(Column).InternalName]