Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

My problem ist related to this question. In order to get the basic statistics I need the total item count. However the basic LINQ query

(from t in Tickets
select t).Count();

or

Tickets.Count();

does take a considerable amount of time (5-10 seconds on my laptop-vm, depending on load). Are there quicker ways to get the count, or is this huge timespan caused by the lack of resources on my machine?

share|improve this question

2 Answers 2

you can use this, its part of that sharepoint object model SPList.ItemCount:

    private static void OpenListItem(string siteURL, string listName)
    {
        using (SPSite site = new SPSite(siteURL))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists[listName];

                Console.WriteLine(list.ItemCount.ToString());

            }
        }
    }

change it to suite your needs, I just made it in a console app :)

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.itemcount.aspx

its designed for a fast and efficent count, if you want the exact ammount use:

    private static void OpenListItem(string siteURL, string listName)
    {
        using (SPSite site = new SPSite(siteURL))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists[listName];

                Console.WriteLine(list.Items.Count.ToString());

            }
        }
    }
share|improve this answer

The only two faster way that I know are:

  • use CAML
  • have an hidden column that keep the number of your records

otherwise I found this thread: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentprevious/thread/6a98b55c-2454-49c0-beb8-a57fe9b8b25a/

I had wrote this post where I thought that another way could be use the search service.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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