2

Hi Guys I have this problem:

I query a list using Caml.

items = list.GetItems(query);

This returns 6 items and works ok. Then I do:

foreach (SPListItem item in items)
{
     var title = item["Title"];//this row throws the exception
}

And I get the following exception.

Argument Exception - Value does not fall within the expected range.

What I tried:

The item is not null.

I iterated through the item fields, got their internal names and all the fields are there.

The field name is correct.

I increased the List View Lookup Threshold from 8 up to 1000(does not seem help).

If that matters - the code is used in the execute method of a timer job(I restart the timer service every time so the code is up to date).

Any ideas?

Edit 1

Here is the Caml Query:

SPQuery query = new SPQuery();
string workingCaml = "<Where><BeginsWith><FieldRef Name=\"ContentTypeId\"/><Value Type=\"ContentTypeId\">0x01005AC98BAE1E70FB4A91957E3135BF85B3</Value></BeginsWith></Where>";
query.Query = workingCaml;
  • 2
    Can you include your query? Have you tried by including Title in the ViewFields property of the query? – Naim Murati Mar 19 '14 at 7:28
  • Yes I tried that, it didn't work – Gesh Mar 19 '14 at 7:33
  • 1
    Hi, try this. Instead of the Title, fetch the ID:- item["ID"] Let me know if this works.. Then, I can suggest a possible solution.! Also I want to know if you are using SPQuery object? – variable Mar 19 '14 at 7:35
8

If fetching of item["ID"] instead of 'Title' works AND If you are using the SPQuery object. Then, include the columns that you want to fetch in the ViewFields property of SPQuery. This will resolve your issue.

Reference: http://discoverlars.wordpress.com/2012/01/24/argumentexception-value-does-not-fall-within-the-expected-range-error-using-fields-on-splistitem/

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.