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

1

7

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>";
Jurist answered 9/11, 2010 at 12:12 Comment(2)
What is the value of the variable _id?Piles
Try this tool to help you u2u.net/res/Tools/CamlQueryBuilder.aspxPiles
C
10

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;
Cornea answered 9/11, 2010 at 14:24 Comment(1)
Dang beat me to it. This is exactly what she needs. :)Insane

© 2022 - 2024 — McMap. All rights reserved.