SharePoint: How to get Top 5 records by using CAML query from a list

梦想的初衷 提交于 2019-12-01 15:44:13

You could set the RowLimit property of your SPQuery object.

The <RowLimit> tag is in the schema definition of a view (direct child of <View>) and therefore cannot be nested inside a <Query> tag.

Sunil Kumar Pashikanti

The below code shows top 5 records from the list (by using CAML query).

SPQuery spQuery = new SPQuery();
spQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='FALSE'/></OrderBy>";
spQuery.RowLimit = 5;

If you want to construct other simply caml queries try this tool. http://www.camldesigner.com/

P.s. tool doesn`t construct a "paginate" caml queries with SPListItemCollectionPosition.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!