My SharePoint site having a Large List that contains large data I have to fetch all items and show them in gridview? I am using below code and getting the below error
"The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator"
private void GetData()
{
using (SPSite site = new SPSite("URL"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList("BulkData");
if (list != null)
{
SPQuery query = new SPQuery();
query.Query = "<Where><IsNotNull><FieldRef Name=\"Title\" /></IsNotNull></Where>";
query.QueryThrottleMode = SPQueryThrottleOption.Override;
SPListItemCollection items = list.GetItems(query);
int itemCount = items.Count;
StringBuilder sb = new StringBuilder();
string str1 = string.Empty;
foreach (SPListItem item in items)
{
int i = 1;
sb.Append("\r\n").Append(Convert.ToString(item["Title"])).Append("\r\n");
i++;
}
Log(sb);
}
}
}
}
region Log File
public void Log(StringBuilder ErrorMessage)
{
string LogFileTime = DateTime.Now.ToString("ddMMyyyyHHmmss");
string LogFilePath = Server.MapPath(@"~\\Logs\");
if (!File.Exists(LogFilePath + "BulkData" + LogFileTime + ".txt"))
{
var LogFileName = File.Create(LogFilePath + "BulkData" + LogFileTime + ".txt");
var WriteToLogFile = new StreamWriter(LogFileName);
WriteToLogFile.Write(ErrorMessage);
WriteToLogFile.Close();
LogFileName.Close();
}
}
#endregion