2
votes

I have made a query against a list. I want to get the last modified item which meets a certain condition, and my query looks like this:

<Query><OrderBy><FieldRef  Name='Modified' Ascending='FALSE' /></OrderBy><Where><Eq><FieldRef Name='kortnummer'/><Value Type='String'>kv11</Value></Eq></Where></Query>

I get the listitems i need, just not in the right order. Changing Ascending to true does nothing, so obviously there is something with the OrderBy clause that is not right..

According to MSDN it should be possible to order by Modified.

Any idea why my OrderBy does not work?

2
can you please post your code to execute that query? maybe you're just sending that additional <Query> tagRubens Farias
Yeah, because if you get the query wrong, it will return all the results.Janis Veinbergs
Thanks, that helped me solve it! I had it without <Query> at first but then it didn't return anything at all. Turned out that i just should have changed the datatype of the where fieldref to 'Text' :)brysseldorf

2 Answers

3
votes

I always put the OrderBy after the Where.

Otherwise you could make sure that you are using the internal name. I usually use SharePoint Manager 2007 to get the internal field names. Codeplex SharePoint manager

I can see that on a list in my SharePoint, the modified column internal name is "Last_x0020_Modified".

1
votes

If you're doing this in a C# string to get an SPListItemCollection, you don't need "<Query></Query>" tags.