SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to return only the count of the rows from a Sharepoint query? I would like to get only the count of the result returned by sharepoint query.

share|improve this question

If you use CAML to get list items (which is the fastest way of retrieving items), it is just enough to get ids of items to be able get the count:

//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'/>",
    Query = q,
    IncludePermissions = false,
    RowLimit = 20000
var items = lst.GetItems(query);
var count = items.Count;
share|improve this answer
+1 using viewfields with a query is the only way. There is no "Count" function. – Kit Menke Jan 3 '12 at 15:18

Your Answer


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.