I want to get the number of comments from the list "Comments" of a blog site. To do that, I have a query with this code:
using (SPWeb oWebsite = oSiteCollection.OpenWeb(new Guid(WebId)))
{
SPList oList = oWebsite.Lists["Comentarios"];
if (oList.ItemCount > 0)
{
var query = new SPQuery()
{
Query = "<Query><Where>" +
"<Eq>" +
"<FieldRef Name='ows_PostID' LookupId='TRUE'/>" +
"<Value Type='Lookup'>" + IDEntryBlog + "</Value>" +
"</Eq>" +
"</Where></Query>",
// ViewFields = "ID",
//ViewFieldsOnly = true,
IncludePermissions = false,
RowLimit = BlogInfo.MaxNumberOfComments
};
SPListItemCollection items = oList.GetItems(query);
ncomments = items.Count;
}
}
I always receive the total number of elements. Have a look to the xml content of items: http://pastebin.com/g2nGpLKj
What am I doing wrong?
Query
with a capitalQ
in your query tag. But if this is server side code, as it looks like, you should omit the<Query>
part from the query – Robert Lindgren Oct 9 '15 at 12:23