views:

3091

answers:

1

Hi I am developing using the SharePoint namespace and I ran into the following error when I try to retrieve a Title field from the list items.

"Value does not fall within the expected range"

I know however that the field exists because I printed out all the fields.

string value = (string)listItem[listItem.Fields["Title"].Id];
Console.WriteLine("Title = " + value);

Update: To what extent does the View that was used to retrieve the list items play a role in what fields will be available? This code fails with the same exception:

SPListItemCollection items = list.GetItems(list.DefaultView);
foreach (SPListItem listItem in items)
{
  try
  {
    Console.WriteLine("Title = " + listItem.Title);
  }
  catch (Exception e) 
  { 
    Console.WriteLine("Exception: " + e.Message); 
  }
}

In both cases the list.DefaultView property was used to retrieve the list items.

+1  A: 

The "Title" field may exist in the list but not in the default view. Can you do this?

foreach (var item in list.Items) Console.WriteLine((string)item["Title"]);
vitule
Any attempt to reference item["Title"] throws that exception.
Ries