SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get the previously (last) added item id by the current logged in user in a custom list?

I created a custom list to get username, IP address, and check-in time. From a web part the user who logged in will submit these fields. Next time when he logs in again to the site I want to rerun the previously added IP address, check-in time, ID, so that I can do some calculations. So how can I get these things done?

share|improve this question

Sharepoint generates ids which are always unique and incremental. So you could write a CAML query for the List to get all the items added for the current user and then select the ListItem with max value of id.

share|improve this answer
Hi Pushpendra, can you give me any like that have simple example using CAML. – ghousepasha Jul 28 '13 at 18:13

This query will get you the latest item added by a user in the List.

SPQuery query = new SPQuery();
query.Query = "<Where>" +
                  "<Eq><FieldRef Name='Author' /><Value Type='User'>user.Name</Value></Eq>" +
                "</Where>" +
              "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
query.RowLimit = 1;
query.ViewFields = "";
query.ViewFieldsOnly = true;
share|improve this answer
Should that be descending to get the latest item? – Dave Paylor Jul 28 '13 at 20:23 should be descending... – Pushpendra Jul 30 '13 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.