Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

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.

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
1  
Should that be descending to get the latest item? –  Dave Paylor Jul 28 '13 at 20:23
    
Yes..it should be descending... –  Pushpendra Jul 30 '13 at 16:55

Your Answer

 
discard

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.