4

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);
  • 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
  • hi, I am facing similar problem. I tried method 1: using internal name 2. add viewfields in caml query 3. set list view threshold in Resource throttling am I missing something?\ – Salim Mandrekar Mar 21 '17 at 6:07
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.

  • 1
    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 '14 at 14:18
3

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.

2

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

2

be sure that you include that field in the viewfields

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

1

I suggest you can check the thread: https://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.

0

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

  • 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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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