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?

2 Answers 2


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.

  • Hi Pushpendra, can you give me any like that have simple example using CAML. Jul 28, 2013 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;
  • 1
    Should that be descending to get the latest item? Jul 28, 2013 at 20:23
  • Yes..it should be descending...
    – Pushpendra
    Jul 30, 2013 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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