How to get the last item created by a specific user at the request of CAML

I am trying to get the very last element created by a specific user at the request of CAML, but it seems to return all the data created by everyone.

Help me please.

Here is my code:

string lifestyleQuery = @"<Where><Eq><FieldRef Name='Author' /><Value Type='Text'>" + _id + @"</Value></Eq></Where>"; 
+7
c # sharepoint caml splistitem
source share
2 answers

Try the following:

 SPQuery query = new SPQuery(); query.Query = @"<Where><Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Integer'>" + _id + @"</Value></Eq></Where><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>"; query.RowLimit = 1; 
+10
source share

Use this to get the current date in an acceptable CAML format:

 DateTime dt = DateTime.Now; string currentDate = String.Format("{0:yyyy-MM-ddThh-mm-ssZ}", dt); 

This request will provide you with user-created items from the newest to the oldest. I'm not sure how you will return only one node.

 string lifestyleQuery = @"<Query><OrderBy><FieldRef Name='Date'></OrderBy><Where><And><Eq><FieldRef Name='Author' /><Value Type='Text'>" + _id + @"</Value></Eq><Lt><FieldRef Name='Date' /><Value Type='DateTime'>" + currentDate + @"</Value></Lt></Where></Query>"; 

You may need to work a bit with the query to get the correct column names (etc.), but I think this might be what you are asking?

0
source share

All Articles