Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
share|improve this question
1  
can you show your code? –  Prashant Lakhlani Oct 31 '12 at 8:49
    
where are you using this code, web part? event receiver, console application? –  Prashant Lakhlani Oct 31 '12 at 11:06
    
in a class that implement the ICustomMapping interface –  Gaetanu Oct 31 '12 at 16:55
    
help me guys!!!! –  Gaetanu Nov 2 '12 at 9:54

6 Answers 6

You can retrieve the value by using item.Properties["Name"] instead. We ran into the same problem and while I wasn't able to find a root cause this worked as a fix.

share|improve this answer
    
Thanks, Shane! I was so frustrated by this error and your tip fixed it. Weird that it works on every field except this one boolean field. Stupid SharePoint. –  Peter Walke May 8 at 14:18

How do you get this SPListItem in the first place? For example, when item is retrieved by CAML query without necessary fields defined in ViewFields section, it may lead to exception when retrieving such a field.

share|improve this answer

Try to open your List/Item with Sharepoint Manager tool and check exactly what is the correct internal name of your field.

share|improve this answer
    
I did with power shell, anyway I tried with SPM and the internal name is the same. How you can see I try to get the value by the GUID too –  Gaetanu Oct 31 '12 at 10:54
    
Something might be happening with the item. Anyway, try this: 'item.Fields["MyCustomField"]' –  TheBigCheese Oct 31 '12 at 10:55

I think that you get SPListItemCollection from SPView, but this SPView does not contains needed field

share|improve this answer

I suggest you can check the thread: http://stackoverflow.com/questions/17875571/sharepoint-2010-value-does-not-fall-within-the-expected-range

It's refered to the "List View Lookup Threshold" parameter on the Central Administration.

share|improve this answer

SharePoint 2013, Central Administration, Select web application, Resource Throttling under ribbonbutton flyout General Settings and change List View Lookup Threshold from 8 to something higher (depending on how much lookup, taxonomy, user, etc fields you have).

Best way to test is add all your fields to the default view and see if it can render.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.