I got this error while trying to retrieve item from a SharePoint 2010
list using SharePoint object model. The full error message is "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator".
You can also check out my previous posts on:
By default SharePoint has threshold limit of 5000 items. If the list grow further then it will give performance issue. If you are trying to query item from a very larger list then you may face this issue.
To resolve the issue you can set EnableThrottling = false; for the particular list before retrieving.
Below is a sample code:
using (SPSite thisSite = new SPSite(ServerInfo.SharePointListUrl.ToString()))
using (SPWeb web = thisSite.OpenWeb())
SPList listCountry = web.Lists["Country"];
listCountry.EnableThrottling = false;
SPQuery objquery = new SPQuery();
objquery.Query = "<Where><Eq><FieldRef Name='Country' /><Value Type='Text'>India</Value></Eq></Where>";
SPListItemCollection items = listCountry.GetItems(objquery);
Now when you try to retrieve the item, it should not give any error.