2

there are 7000 items in my list. i need to filter the list and retrieve result i am using the following code in my webpart.

string query = "<Where><BeginsWith><FieldRef Name='Project' /><Value Type='Text'>ab</Value></BeginsWith></Where>"
SPQuery spquery = new SPQuery();
spquery.Query = query;
ContentIterator iterator = new ContentIterator();
iterator.ProcessListItems(list, spquery, ProcessListItem, ProcessListItemError)

as i am using ContentIterator still it is giving me the error "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator"

Update:

string query2 = @"<Where><Eq><FieldRef Name='Project' /><Value Type='Text'>11759</Value></Eq></Where>"; 
SPQuery spquery = new SPQuery(); 
spquery.RowLimit = 10; 
spquery.Query = query2; 
spquery.QueryThrottleMode = SPQueryThrottleOption.Override; 
ContentIterator iterator = new ContentIterator(); 
iterator.ProcessListItems(list, spquery, ProcessListItem, ProcessListItemError); 

In every case weather I used SPCollectionItem or Iterator. when ever I am passing the where condition in spquery. same error comes.

Stefan
  • 14,530
  • 4
  • 55
  • 62
saurabh
  • 33
  • 2
  • 9

5 Answers5

2

To efficiently use ContentIterator and avoid throttle exception, you should explicitly include OrderBy clauses.

Try to use ContentIterator.ItemEnumerationOrderByNVPField which actually enables the index to be used.

For more details,check this out

http://extreme-sharepoint.com/2012/07/17/data-access-via-caml-queries/

gravinskm
  • 21
  • 2
1

Likely because the the Field you are comparing on is not indexed: http://msdn.microsoft.com/en-us/library/ff798465

If you were to build a query that returns the first 100 items sorted by the ID field, the query would execute without issue because the ID column is always indexed. However, if you were to build a query that returns the first 100 items sorted by a non-indexed Title field, the query would have to scan all 10,000 rows in the content database in order to determine the sort order by title before returning the first 100 items. Because of this, the query would be throttled, and rightly so—this is a resource-intensive operation.

Brian
  • 1,383
  • 3
  • 16
  • 30
0

You either have to ...

  • ... set a RowLimit below the configured threshold on your query.
  • ... or define a query that returns less items.
  • ... or change the threshold of the list.
Community
  • 1
  • 1
Stefan
  • 14,530
  • 4
  • 55
  • 62
  • thanks row limit was defined and what about this query abc it is also giving the same error as number of return result is one – saurabh Jan 07 '12 at 10:45
  • You could set the [SPQuery.QueryThrottleMode Property](http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.querythrottlemode.aspx) to `Override`. Does this change anything? – Stefan Jan 07 '12 at 11:53
  • Updated code string query2 = @"11759"; SPQuery spquery = new SPQuery(); spquery.RowLimit = 10; spquery.Query = query2; spquery.QueryThrottleMode = SPQueryThrottleOption.Override; ContentIterator iterator = new ContentIterator(); iterator.ProcessListItems(list, spquery, ProcessListItem, ProcessListItemError); in every case weather i used SPCollectionItem or Iterator. when ever i am passing the where condition in spquery. same error comes. – saurabh Jan 07 '12 at 15:00
0

have you seen this:

msdn link

hmmz, just tried this and it still gave an error. If I use this however I can iterate over way more than 7k listitems:

private int GetItems(SPList list){
    var query = new SPQuery();
    query.Query = "";
    query.QueryThrottleMode = SPQueryThrottleOption.Override;
    var items = list.GetItems(query);
    return items.Count;

}

so my advice is to just use the list.getitems

Tjassens
  • 922
  • 6
  • 9
0

You just need to change your query.

    //Keep your query inside <View></View> tag.
    string query = "<View><Where><BeginsWith><FieldRef Name='Project' /><Value Type='Text'>ab</Value></BeginsWith></Where><View>" 
    SPQuery spquery = new SPQuery(); 
    spquery.Query = query; 
    ContentIterator iterator = new ContentIterator(); 
    iterator.ProcessListItems(list, spquery, ProcessListItem, ProcessListItemError) 

Now run the program and it will work.