Caml query not returning fileleafref

Senior Member

I have a CAML query that I am running through the REST api, the simple example below requests 2 fields - FileLeafRef and CustomField. Custom field is simple a text field, nothing special.

CustomField is returned whereas FileLeafRef is not.

If I run the same CAML via CSOM or the old WCF/soap based services then FileLeafRef is returned...


<View Scope="RecursiveAll">
        <FieldRef Name="FileRef" />
        <Value Type="Text">/SomeSite/SomeDocumentLibrary/SomeFile.txt</Value>
    <FieldRef Name="FileLeafRef" />
    <FieldRef Name="CustomField" />

I know I can use a $select querystring, but this is on an app that the user can specify any number of columns to retrieve and querystrings have a limit.

So is there something I am missing? Or does REST CAML act differently to the other two...

N.b this is against SharePoint Online


I should add this is being called via a post to an endpoint like'listGuid')/getitems

1 Reply
The column FileRef returns the file URL. In case of FileRef it should be passed to the expands in getItemsByCAMLQuery. Like the code:

const viewFields = `
<FieldRef Name='FileRef' />
<FieldRef Name='ID' />
<FieldRef Name='Title' />

const queryOptions = `<QueryOptions><ViewAttributes Scope='RecursiveAll'/> </QueryOptions>`;
const camlQuery = '';

ViewXml: `<View>${viewFields}${camlQuery}${queryOptions}</View>`
}, 'FileRef')

Please note getItemsByCAMLQuery({
ViewXml: `<View>${viewFields}${camlQuery}${queryOptions}</View>`
}**, 'FileRef')**