3

Trying to fetch data from SharePoint List using CAML query.

Am using the attribute Descending, but does not work as expected.

Please find the code below.

<OrderBy>
    <FieldRef Name='ID' Descending = 'True'/>
</OrderBy>

Above code still fetches the smallest ID(where ID is 1,2,3..so on), in my case it fetches the ID=1

Thanks in advance.

KrankyCode
  • 441
  • 1
  • 8
  • 24

1 Answers1

13

AFAIK, there is no "Descending" attribute for specifying a descending order by.

Instead, you must use the Ascending attribute, and specify "false" as the value.

<OrderBy>
    <FieldRef Name='ID' Ascending='FALSE'/>
</OrderBy>

As you can see from this page

Ascending -- Optional Boolean. This specifies the sort order on a FieldRef element that is defined in a view. The default value is TRUE.

SPArcheon
  • 1,273
  • 1
  • 19
  • 36
  • Thanks SPArchaeologist. Yes, You are right.. was going trough the msdn microsoft site and found the documentation for CAML(http://msdn.microsoft.com/en-us/library/ms442728.aspx). There is no attribute such called as Desecnding. It has only the Ascending attribute with TRUE | FALSE values. Thanks Much.. – KrankyCode Mar 21 '13 at 10:00
  • don't worry, my pleasure - It is a bit "not so intuitive". I would have preferred if they had created an attribute "Direction" with two values "Ascending" and "Descending"... Btw, just to do some random ads - there is a site specific for SharePoint questions in the stack exchange network: link [here](http://sharepoint.stackexchange.com/). If in the future you need anything SharePoint related and you don't receive an answer here on the main site, consider giving it a go. – SPArcheon Mar 21 '13 at 10:47