SharePoint CAML query Orderby does not support descending attribute.?

KrankyCode picture KrankyCode · Mar 21, 2013 · Viewed 12.6k times · Source

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.

Answer

SPArcheon picture SPArcheon · Mar 21, 2013

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.