Here is the code Im using to retrieve the first 4 most upcoming announcements from the OOTB announcements list in sharepoint:
How do I modify this to retrieve the next 4 (5,6,7 and 8) most upcoming events preserving the filters and order bys in my CAML??
Is there a way for me to use an Index variable and iterate?
Or should I go with LINQ's skip and take features?? (I'd like to know how to do it using the CAML query though)
SPList list = web.Lists["Announcements"];
SPQuery spQuery = new SPQuery();
//The following CAML query filters to show the 4 most upcoming announcements.
spQuery.Query = " <Where><And><IsNotNull><FieldRef Name='Title' /></IsNotNull><Or><IsNull><FieldRef Name='Expires' /></IsNull><Geq><FieldRef Name='Expires' /><Value Type='Date'><Today /></Value></Geq></Or></And></Where><OrderBy><FieldRef Name='Created' Ascending='True' /></OrderBy>";
spQuery.RowLimit = 4;
SPListItemCollection oListCollection = list.GetItems(spQuery);
foreach (SPListItem item in oSPListItemCollection)
{
// Check if item exists
if (item != null)
{
Label1.Text = item["Title"].ToString();
}
}