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

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
add comment

1 Answer

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  
+1 using viewfields with a query is the only way. There is no "Count" function. –  Kit Menke Jan 3 '12 at 15:18
add comment

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.