I have the following problem. I have a list with a custom content type, when programmatically I want get an information from my SPListItem I get the following exception: Value does not fall within the expected range.
If I print all the fields of my item I have the field I looking for. I try to get the data by the GUID, by the internal name and so on, but I receive always the same error.
Why?
private static DateTime GetModified(SPListItem item)
{
// I tried it
//string ultimarevisione = item.GetFormattedValue("MyCustomField");
if (item[new Guid("{EA440C5B-845D-482F-8D10-666B06851AFE}")] == null)
return DateTime.Parse(item["StartDate"].ToString());
return (DateTime)item[new Guid("{EA440C5B-845D-482F-8D10-666B06851AFE}")];
}
var field = item.Fields.GetFieldByInternalName("MyCustomField");
//in this way doesn't work too
if (item[field.Id] == null)
return DateTime.Parse(item["StartDate"].ToString());
I got it with a LINQ query
var results = docs.ScopeToFolder(docsList.RootFolder.Url, true)
.Where(p => p.ItemType == SPFileSystemObjectType.File &&
p.ItemType != SPFileSystemObjectType.Folder)
.OrderByDescending(d => d.Modified);