locked
SPQuery with Order By is not working properly RRS feed

  • Question

  • Hi i have document library having custom column named INDEX of type Number and there is some folders and documents in document library like

    File/folder structure in document library

    I have created CAML query to get item having maximum Index value.

    query += "<Where>";
    query += "<IsNotNull>";
    query += "<FieldRef Name='INDEX'/>";
    query += "</IsNotNull>";
    query += "</Where>";
    query += "<OrderBy >";
    query += "<FieldRef  Name='INDEX' Ascending='FALSE' />";
    query += "</OrderBy>";
    
    itemQuery.Query = query; 

    In result i am getting is below which is wrong.

    In result all folders are displaying and then files are displaying.

    enter image description here


    Excepted result should be like below.

    enter image description here

    Can anyone help me in this issue?


    Monday, March 27, 2017 6:30 AM

Answers

  • I have resolve this issue of adding Override='TRUE' property.

    Updated code is below

    query += "<Where>";
    query += "<IsNotNull>";
    query += "<FieldRef Name='INDEX'/>";
    query += "</IsNotNull>";
    query += "</Where>";
    query += "<OrderBy Override='TRUE'>";
    query += "<FieldRef  Name='INDEX' Ascending='FALSE' />";
    query += "</OrderBy>";

    Thanks,

    Kaushal Khamar

    Monday, March 27, 2017 11:53 AM