1

I have more than 10000 items in my list. I have default List View Threshold value as 5000.I want to get the count of items programmatically. How can I get the count? I think here SPListItemCollection.Count won’t work.Is there any other methods?

List View Threshold size for auditors and administrators is 20000 by default.If i am administrator will i get the count from SPListItemCollection?

  • Did you find any appropriate solution for this, I'm stucked to this issue – Rakesh Sadhula May 23 '18 at 6:17
2

For this you need to increase the Threshold value first and then get the list item count. You can increase it either programmatically or powershell or Central admin.

Ex.. through powershell

$WebApplication = Get-SPWeb http://
$List = $WebApplication.Lists["My List"] 
$List.EnableThrottling = $false
$List.Update() 

http://social.msdn.microsoft.com/Forums/sharepoint/en-US/95adcb1f-2b1e-4e26-b352-060731978f41/sharepoint-list-item-count-exceeds-the-threshold-limit?forum=sharepointdevelopmentprevious

Once you get the count revert it back.

http://blogs.msdn.com/b/dinaayoub/archive/2010/04/22/sharepoint-2010-how-to-change-the-list-view-threshold.aspx

0

You will be able to get the total count using the ContentIterator:

It queries the lists in batches and avoids the Throttling Exceptions:

static int exceptions = 0;
static int items = 0;

protected void OnTestContentIterator(object sender, EventArgs args)
{
    items = 0;
    exceptions = 0;
    string query1 = @"<View>
        <Query>
            <Where>
                <And>
                    <BeginsWith>
                        <FieldRef Name='SKU' />
                        <Value Type='Text'>S</Value>
                    </BeginsWith>
                </And>
            </Where>
        </Query>
    </View>";

    ContentIterator iterator = new ContentIterator();
    SPQuery listQuery = new SPQuery();
    listQuery.Query = query1;
    SPList list = SPContext.Current.Web.Lists["Parts"];
    iterator.ProcessListItems(list,
        listQuery,
        ProcessItem,
        ProcessError
    );
}

public    bool ProcessError(SPListItem item, Exception e) 
{ 
    // process the error
    exceptions++; 
    return true; 
}
public void ProcessItem(SPListItem item)
{
    items++;
    //process the item.
}
  • Is it a good way to increment the exception count? – anish Nov 12 '13 at 11:02
  • Just and example from MSDN. The items variable is what we are really interested in. – Vardhaman Deshpande Nov 12 '13 at 11:13
0
SPList.ItemCount property returns the items count of the whole list.

SPQuery query = new SPQuery(); // or SPQuery query = new SPQuery(view); copy query string from a view.
query.QueryThrottleMode = SPQueryThrottleOption.Override;
SPListItemCollection items = list.GetItems(query);
int count = items.Count;
  • By SPQueryThrottleOption.Override what will be the new limit? – anish Nov 12 '13 at 11:00
  • If the user is a local administrator on the server no throttling limits will apply to the query. If the web application security policy grants the user Full Read or Full Control permissions the throttling limit for Auditors and Administrators will apply to the number of items involved in the query and no throttling will apply to the number of Lookup, Person/Group, and Workflow Status fields. Otherwise the [Microsoft.SharePoint.SPQueryThrottleOption.SPQueryThrottleOption.Default] setting will apply to the query. – Klaus Nov 12 '13 at 11:11
  • msdn.microsoft.com/en-us/library/… – Klaus Nov 12 '13 at 11:11
0

Try using

//some query
var title = "<Eq><FieldRef Name='Title' /><Value>task 00001</Value></Eq>";
var q = "<Where>" + title + "</Where>";
var lst = web.Lists["Tasks"];
var query = new SPQuery
{
    ViewFields = "<FieldRef Name='ID'/>",
    QueryThrottleMode = SPQueryThrottleOption.Override
    Query = q,
    IncludePermissions = false,
    RowLimit = 20000
};
var items = lst.GetItems(query);
var count = items.Count;

as shown in this post

  • Here "List View Threshold size for auditors and administrators" is used? – anish Nov 12 '13 at 10:57
  • Enumeration value of Override is 1. If the user is a local administrator on the server no throttling limits will apply to the query. If the web application security policy grants the user Full Read or Full Control permissions the throttling limit for Auditors and Administrators will apply to the number of items involved in the query and no throttling will apply to the number of Lookup, Person/Group, and Workflow Status fields. Otherwise the [Microsoft.SharePoint.SPQueryThrottleOption.SPQueryThrottleOption.Default] setting will apply to the query. – Remko Nov 12 '13 at 11:12
  • added query.QueryThrottleMode = SPQueryThrottleOption.Override – Remko Nov 12 '13 at 11:13
0

Using SPList.ItemCount property worked perfectly for me.

string dump = string.Empty;
foreach (SPList list in SPContext.Current.Web.Lists)
{
   dump += string.Format("List:{0}, Item count:{1}\n", list.Title, list.ItemCount);
}
0

No need for programmed solution. Open the list in SP Designer. Under "List Information" you will see a count total of items on the list.

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.