Get Top 5 list items from Sharepoint List using CAML
This is a sample code for retrieving top 5 items from the SharePoint List.
SPQuery is the SharePoint class to initialize the CAML query.
This following Query will display the top 5 items OrderBy ID as Ascending is false.
SPQuery spQuery = new SPQuery();
spQuery.Query = "<Query>
<OrderBy>
<FieldRef Name='ID' Ascending='False' />
</OrderBy> </Query> ";
spQuery.RowLimit = 5;
This is a sample code for retrieving top 5 items from the SharePoint List.
SPQuery is the SharePoint class to initialize the CAML query.
This following Query will display the top 5 items OrderBy ID as Ascending is false.
SPQuery spQuery = new SPQuery();
spQuery.Query = "<Query>
<OrderBy>
<FieldRef Name='ID' Ascending='False' />
</OrderBy> </Query> ";
spQuery.RowLimit = 5;
How to get particular columns using caml query
ReplyDeleteHi viswanath,
DeleteIn this query i am using viewfields to get the particular columns.
SPQuery query = new SPQuery();
query.Query = string.Concat(
"",
"",
"Not Started",
"",
"",
"",
"",
"");
query.ViewFields = string.Concat(
"",
"",
"",
"");
query.ViewFieldsOnly = true; // Fetch only the data that we need.
Hi why u r using ascending=false in this queries....
ReplyDeleteHi guna,
ReplyDeleteThat is used to sort the items by ID column