Search code examples
c#sharepointcamlsplistitem

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>";

Solution

  • 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;