Condividi tramite


Programmatically Using the Object Model Override for the List View Threshold

In this post titled "How to change the List View Threshold and Other Resource Throttling Settings", I described why you might want to use the "List View Threshold for Auditors and Administrators", which is 20,000 by default. This limit is higher than the default 5,000 List View Threshold that gets applied to all regular users.  If you decide you do want to use this higher limit for some custom code or application, then the following conditions must all be met:

  1. The Object Model Override must be set to On.
  2. The code being run must be run as a user with "Full Control" or "Full Read" permissions.
  1. The code must explicitly request the override when using SPQuery, by setting the SPQueryThrottleMode.

 

If any of those conditions are not met, then the query will be subject to the regular List View Threshold, rather than the Auditor/Administrator one which is typically higher.

 

In this post, I'll describe how to go about doing this:

 

First, you have to make sure your Object Model Override is enabled (It is ON by default, so unless you've changed it, you are fine).

 

Next, you'll need to grant sufficient privileges to the account that will perform these queries ("Full Control" or "Full Read"). Here's how to do that:

In Central Admin:

-          Click “Application Management”

-          Click “Managed Web Applications”

-          After selecting a specific Web Application, click “User Policy” in the Ribbon

-          Click “Add Users”

-          Select Zone (default: All Zones)

-          Enter Permission level (either of these will suffice)

o   Full Control

o   Full Read

 

Optionally, you may want to consider changing the List View Threshold for Auditors or Administrators to a different number. For example, if you know you don't need all 20,000, then it would be a good idea to lower that number to make sure custom code does not accidentally get written inefficiently without being noticed.

 

Now you're ready to use the List View Threshold for Auditors and Administrators. To do so, running as that user will "Full Control" or "Full Read", you will need to run code that looks something like this:

SPQuery q1 = new SPQuery();

q1.QueryThrottleMode = SPQueryThrottleOption.Override;

rootweb.Lists["Announcements"].GetItems(q1)…

 

There are 3 different options for SPQueryThrottleOption:

  • Default – Normal behavior where all users who are not web server box administrators will be subject to the List View Threshold, including users with "Full Read" or "Full Control" permissions. This is the default behavior unless otherwise specified.
  • Override – if user has “Full Control” or "Full Read" permissions, the List View Threshold for Auditors and Administrators will apply to this SPQuery, and List View Lookup Threshold will not be applied. For more info on what the List View Lookup Threshold does, read this post.
  • Strict – List View threshold will apply for everyone, including web server box administrators. You can use this option to make sure that your code does not cause server stress even if it is being run as the box administrator on one of the web servers, since box administrators are not subject to the thresholds so may inadvertently slow down the servers.

 

Thanks for reading, please let me know if you have any questions.

 

Dina Ayoub

Program Manager on SharePoint, MSFT.

Comments

  • Anonymous
    April 14, 2011
    Hi! Thanks for your post. I have a one question, How can I modify views columns ( for eg. I want to check show all items in this view), is there a way to check that? Thanks!!!

  • Anonymous
    April 15, 2011
    Sorry puru, I don't understand the question. To modify a view's columns you use the list or library tab in the ribbon, then modify view, where you should be able to specify the columns and the items to show in the view.

  • Anonymous
    April 27, 2011
    Hey Dina! Thanks for your response. Using object model can I check "show all items in this view" (Which is in Filter section) in Discussion List. By default its unchecked. so , I want to check that radio button using SP object model. Hope that you can help me.

  • Anonymous
    April 29, 2011
    Hi Puru, I think the UI will select “Show all items in this view” when the <Where> is empty or missing in the view definition.  If that’s correct, then the answer is “modify SPView.Query so that the <Where> is empty, or to remove <Where> from it.” You should double-check the statement “by default it’s unchecked” though, since last I checked, the OOB Discussion Board views had no filters. Let me know if that helps.

  • Anonymous
    June 16, 2011
    We are using web services to access SharePoint from our client application.  Can this be used for client applications via either web services or Client Object Model?

  • Anonymous
    June 27, 2011
    Hi Trevor, Am also trying to access via Web Services. To my knowledge, It's not possible to specify QueryThrottleMode in Web Service Call. Because we are just passing Query as XML. So I've changed my code to use pagination and retrieve list items as Batches(2000 each call). Add below code where ur getting results. This string has next page pointer. listNextPagePointer = listItem.ChildNodes[1].Attributes["ListItemCollectionPositionNext"].Value; In WebService call add below code. XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");                    nextPagePointer = "<Paging ListItemCollectionPositionNext='" + listNextPagePointer + "' />";                    nextPagePointer = nextPagePointer.Replace("&", "&");                    ndQueryOptions.InnerXml = nextPagePointer; listViewNode = ls.GetListItems(listName, null, ndQuery, ndViewFields, ListRowLimit.ToString(), ndQueryOptions, null);

  • Anonymous
    March 23, 2012
    Hi Dina, I have a list in production with 30,000 + items . i want to filter records , but the filter is not working .User should be able to rearch records in the first 100 or may be the last 100 of the 30000 records please help

  • Anonymous
    March 21, 2013
    Dina, Thank you for sharing this. Enabling ""Full Control" or "Full Read" to users does that mean they have such permissions for the whole webapplication? We are created a custom webpart that filters a huge list (25.000 items and more). The users that wants to view the data are not supposed to have this kind of permissions.

  • Anonymous
    September 11, 2013
    thanks, it seems only object model is the way to change the SPQueryThrottleOptions