How to get Single Record from Sharepoint Library when Items in library are more than List Threshold value?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/118030

  •  29-09-2020
  •  | 
  •  

Frage

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."

War es hilfreich?

Lösung

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/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top