SPSite oSPsite = new SPSite(SPContext.Current.Site.ID);
SPWeb oSPWeb = oSPsite.OpenWeb();
SPList list = oSPWeb.Lists["ListName"];
SPQuery query = new SPQuery();
query.RowLimit = 1;
query.Query = "<OrderBy><FieldRef Name='ID' Ascending='FALSE'/></OrderBy>";
SPListItem maxItem = list.GetItems(query).Cast<SPListItem>().FirstOrDefault();
int lastItemId = -1;
if (maxItem != null)
{
lastItemId = maxItem.ID;
}
No comments:
Post a Comment