SharePointAds TextOnly

Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, 27 August 2009

Sharepoint: How to get MAX id of list?

How can we get MAX id of any present list?
-> Simplely use following code
(*Note: insert your list name rather 'List_Name')

public string MaxListId()
{
SPWeb web = SPContext.Current.Web;
SPList oList = web.Lists["List_Name"];
SPQuery query = new SPQuery();

query.Query = "";
SPListItemCollection items = oList.GetItems(query);

DataTable dtmax = new DataTable();
dtmax = items.GetDataTable();

string maxId = "";
foreach (DataRow row in dtmax.Rows)
{
maxId = row["ID"].ToString();
break;
}

return maxId;
}


--