CSOM CAML 按列表项集合文件属性查询顺序

CSOM CAML Query order by list item collection file properties

我如何更新以下代码以按 ListItemCollection.File.Name 或其他文件属性排序?

using (ClientContext spClientContext = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, _clientId, _clientSecret))
{
    if (spClientContext != null)
    {

        CamlQuery camlQuery = new CamlQuery();

        camlQuery.FolderServerRelativeUrl = getSiteUrlAbsolutePath(siteUrl) + "/Shared Documents/" + folderPath;

        
        camlQuery.ViewXml = "<View Scope="RecursiveAll">" +
            "<Query>" +
            "<Where>" +
            "<Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq>" +
            "</Where>" +
            "<OrderBy><FieldRef Name=\"item.File.Name\" Ascending=\"FALSE\"/></OrderBy>" +
            "</Query>" +
            "</View>";

        List list = spClientContext.Web.Lists.GetByTitle("Documents");

        ListItemCollection listItems = list.GetItems(camlQuery);

        spClientContext.Load(listItems,
                             items => items.Include(
                                 item => item.DisplayName,
                                 item => item.FileSystemObjectType,
                                 item => item.File,
                                 item => item.File.Name,
                                 item => item.File.Author,
                                 item => item.File.ModifiedBy,
                                 item => item.File.ListItemAllFields["Created"],
                                 item => item.File.ListItemAllFields["Modified"],
                                 item => item.File.ListItemAllFields["FileRef"],
                                 item => item.File.Length));

        spClientContext.ExecuteQuery();

        if (listItems != null && listItems.Count > 0)
        {
            foreach (ListItem item in listItems)
            {
                if (item.FileSystemObjectType.Equals(FileSystemObjectType.File))
                {
                    // Do Stuff
                }
            }
        }
    }
}

我尝试在 FieldRef item.File.Name 上使用 order by 子句更新 CAML 查询,但没有用。 SharePoint/CAML 查询非常新,所以通常不确定如何处理查询中的内部对象。感谢您的帮助!

你可以使用 FileLeafRef 按文件名排序,如下所示:

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