Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the latest item created by a specific user by CAML query

I am trying to get the most recent item created by a specific user by CAML query but it seems to return all the data created by everyone.

Help please.

Here's my code:

string lifestyleQuery = @"<Where><Eq><FieldRef Name='Author' /><Value Type='Text'>" + _id + @"</Value></Eq></Where>";
like image 281
janejanejane Avatar asked Nov 09 '10 12:11

janejanejane


1 Answers

Try this:

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;
like image 58
Rich Bennema Avatar answered Nov 12 '22 16:11

Rich Bennema