I've created the following method in a class which is intended to fetch all items in a SharePont list and load them into my entity:
public List<ItemEntity> FetchItems(SPList list)
{
// build the CAML query of field names that we wish to retreive
var query = new SPQuery
{
ViewFields = string.Concat("<FieldRef Name='Modified' />",
"<FieldRef Name='Modified By' />",
"<FieldRef Name='Created' />",
"<FieldRef Name='Created By' />")
};
SPListItemCollection items = list.GetItems(query);
return (from SPListItem item in items
select Load("", // item id
"", // content type
"", // display name
"", // name
"", // title
"", // url
"", // author
"", // editor
Convert.ToDateTime(item["Modified"]), // date time modified
item["Modified By"].ToString(), // modified by
Convert.ToDateTime(item["Created"]), // date time created
item["Created By"].ToString() // created by
)).ToList();
}
For some reason that I don't understand it's throwing the following error:
Value does not fall within the expected range.
I thought this could be something to do with the results returned by my CAML query, but even then I restricted it down to meta data fields (which I believe should exist on every file) and unfortunately I'm still receiving the error. Where am I going wrong?