I'm trying to work with large list but every time I do an operation on a list I have an exception because I have more than 5000 items in my list.


If I do this code I have the exception. sPList1.Folders.Count

How can I work with large list without enabled throttling?

EDIT: I don't understand how to use the query to check if there are folders:

query.QueryThrottleMode = SPQueryThrottleOption.Override;

My exception is thrown when i do:

if (sPList1.Folders.Count <= 0)

Here is the exception when I attempt to perform an action:

        SPQuery query = new SPQuery();
query.QueryThrottleMode = SPQueryThrottleOption.Override;//execute query in admin and bypass throttling
query.Query = "<Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where>";//caml to count folder
SPListItemCollection listitem = null;
listitem = sPList1.GetItems(query);

2 Answers 2


You can use:

query.QueryThrottleMode = SPQueryThrottleOption.Override;

by executing the query as a super user.

SharePoint 2010 List Throtelling

Try the following code to get the items based on the folder,

using(SPSite site = new SPSite("site url"))
  using(SPWeb web = site.OpenWeb())
    SPFolder folder = web.GetFolder("/Docs/folder1");
    if(folder.ItemCount > 0)
      SPList list = web.Lists.TryGetList("ListName");
      SPQuery query = new SPQuery();
      query.Folder = folder;
      SPListItemCollection listitem = list.GetItems(query);
  • Is above solution works for you?
    – Hardik
    Commented Jun 2, 2016 at 15:21
  • Thanks for your solution but with this how can i check if list has folder Commented Jun 2, 2016 at 15:33
  • it is just overriding the threshold problems querying the list.
    – Hardik
    Commented Jun 2, 2016 at 15:35
  • Did you still get an error?
    – Hardik
    Commented Jun 2, 2016 at 15:45
  • yes because i don't understand how to use camlquery to check if splist has folders Commented Jun 2, 2016 at 18:50

You can also get the items in pages, in one page will be 5000 items, and if it is not the last page, you have a pointer to the next page. Finally put the query to a do-while loop. This code works for me in powershell, but in C# it will be similar.

$Ids = @()
$list = $rootWeb.Lists.GetByTitle($listName)
$qCommand = @"
<View Scope='RecursiveAll' >
<RowLimit Paged="True">5000</RowLimit>
    <ViewAttributes Scope='RecursiveAll' />

$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = $qCommand


    $listItems = $list.GetItems($query)
    $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

$i = 0
foreach ($item in $listItems)
    if ($item["TaskStatus"] -eq "Nezačaté" -and $item["PosielatUpozornenia"] -ne $false)
       $Ids += $item.Id
 while ($query.ListItemCollectionPosition -ne $null)
 echo $Ids.Count

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.