0

I am trying to get single record from Large Sharepoint library using SPQuery/CamlQuery. The List View Threshold value and List View Threshold for auditors and administrators value is set to 2000. When I execute Query on List using splist.GetItems(SPQuery) method,It is failing. I have set the Rowlimit to 1. All Fields/Columns in the Query are Indexed but these are Managed Metadata Columns having single value. It is throwing the error as "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator."

  • What does your code look like? – Eric Alexander Oct 14 '14 at 14:06
0

You can use SPQueryThrottlingOption API for achieving the thing that you needed. If number of items in list > its threshold limit, then even fetching some items like 10 or 100 from list will not give you result. Because it first sort all of items present in list then will return top 10 or 100 items.

To overcome this part, you can either increase throttling limit from Central Admin or you can use below code to achieve the same.

using (SPSite theSite = new SPSite("http://foo")) 
{
using (SPWeb theWeb = theSite.RootWeb)
{
SPList theList = theWeb.Lists["My List Name"];     
SPQuery qry = new SPQuery();
qry.QueryThrottleMode = SPQueryThrottleOption.Override; 
SPListItemCollection coll = theList.GetItems(qry);

     //do something with the data
}
}

SPQueryThrottlingOption override the Central Admin throttling by Object Model. You should run your code as a administrator for that.

The other way you can skip to throttling by Content Iterator

below is the code for the same:

ContentIterator ci = new ContentIterator("Single Item Example);
SPQuery qry = new SPQuery();
qry.Query = "<Where><Eq><FieldRef Name='Colour'/><Value Type='Text'>Pink</Value></Eq></Where>";
qry.Query = qry.Query + ContentIterator.ItemEnumerationOrderByNVPField;
ci.ProcessListItems(list, qry,
    delegate(SPListItem item)
    {
         // Do stuff with the item
    },
    delegate(SPListItem item, Exception ex)
    {
      // Handle an exception. Return TRUE to rethrow the exception, FALSE to keep iterating  return false;
    }
 );

References:http://msdn.microsoft.com/en-us/library/ff798376.aspx http://www.novolocus.com/2012/07/13/dealing-with-large-lists-part-3-the-contentiterator/

  • I tried to use SPQueryThrottleOption.Override previously but I think It will increase the limit upto "List View Threshold for auditors and administrators" value.But in my scenario both List View Threshold and List View Threshold for auditors and administrators value is same as 2000.Another thing is that the columns used in query are indexed. – Ulhas Chalawade Oct 14 '14 at 11:46
  • See my edited post – ateet Oct 14 '14 at 12:04

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.