0

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.

Microsoft.SharePoint.SPQueryThrottledException

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);
1

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 Jun 2 '16 at 15:21
  • Thanks for your solution but with this how can i check if list has folder – user1898765 Jun 2 '16 at 15:33
  • it is just overriding the threshold problems querying the list. – Hardik Jun 2 '16 at 15:35
  • Did you still get an error? – Hardik Jun 2 '16 at 15:45
  • yes because i don't understand how to use camlquery to check if splist has folders – user1898765 Jun 2 '16 at 18:50
0

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' >
<Query>
  <Where>
  </Where>
</Query>
<RowLimit Paged="True">5000</RowLimit>
<QueryOptions>
    <ViewAttributes Scope='RecursiveAll' />
</QueryOptions>
</View>
"@

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

$ctx.Load($list)
$ctx.Load($list.RootFolder)

do 
{
    $listItems = $list.GetItems($query)
    $ctx.Load($listItems)
    $ctx.ExecuteQuery()
    $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, privacy policy and cookie policy

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