logo
search
SharePoint Document Issues

How to Fix SharePoint CAML Query Returning Folders Instead of List Items

John WilsonJohn Wilson Oct 12, 2026 869 views

Question details

The user needs to retrieve specific list items via a CAML query without fetching the parent folders or receiving null values for custom fields.

How to Fix SharePoint CAML Query Returning Folders Instead of List Items
Product
SharePoint Online
Device & OS
not provided
Scenario
Executing a SharePoint GetItems CAML query to retrieve list items that contain custom fields like FirstName, LastName, and Manager.
Observed behavior
The query returns folders and more items than expected. Only the Title field is populated, while the custom fields return as null.
Before you start

Ensure you have access to the codebase or the query editor where your SharePoint CAML queries are constructed and executed.

Solution 1Recommended

Add the RecursiveAll Scope to the CAML View Element

By modifying the scope of the CAML query, you force SharePoint to bypass the default root-folder limitation and traverse the entire list hierarchy to fetch actual items.

By default, SharePoint queries often search only the root folder level, which is why your query is returning the folders themselves rather than the items inside them. This also explains why custom fields are null—folders generally only populate the Title field.

Adding the RecursiveAll scope ensures that the query traverses all folders and subfolders to fetch the specified list items alongside their populated custom fields.

1
Locate the CAML query

Open your development environment or query editor and navigate to the specific CAML query string used for the GetItems request.

2
Find the View element

Identify the <View> XML tag wrapping your query parameters.

3
Apply the recursive scope

Add the Scope attribute to the View tag so it reads: <View Scope="RecursiveAll">.

4
Set the row limit (Optional but recommended)

To prevent list view threshold errors, ensure you have a reasonable row limit defined within the view, such as <RowLimit>5000</RowLimit>.

5
Execute and verify

Run the query again. The folders will be bypassed, and the custom fields like FirstName, LastName, and Manager should now be populated properly.

Add the RecursiveAll Scope to the CAML View Element
Query Syntax Example: Your updated XML should look similar to this: <View Scope="RecursiveAll"><RowLimit>5000</RowLimit></View>
Free Microsoft Office alternative

Analyze Exported SharePoint Lists with WPS Office

While resolving complex SharePoint development queries, you might frequently need to verify exported list data. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office for analyzing CSV and Excel files exported directly from SharePoint.

  1. 1. Download WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
  2. 2. Export SharePoint Data: From your SharePoint list, use the 'Export to Excel' or 'Export to CSV' function to download your queried data.
  3. 3. Open and Analyze: Double-click the downloaded file to open it seamlessly in WPS Spreadsheet for data formatting and analysis.
Fully compatible with Microsoft Excel (.xlsx) and CSV formats exported from SharePoint.A free and lightweight alternative to heavy Microsoft Office installations.Intuitive tabbed interface makes comparing multiple SharePoint data sheets easy.Seamless migration with familiar UI and no steep learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why do custom SharePoint fields return as null in my CAML query?

This usually happens when the query retrieves folder objects instead of actual list items. Folders do not inherently contain your custom item fields (like FirstName or Manager), so only the Title field populates. Using the RecursiveAll scope targets the items inside the folders instead.

What is the difference between Recursive and RecursiveAll in a CAML query?

The 'Recursive' scope fetches all list items across all folders but excludes the folders themselves from the results. 'RecursiveAll' fetches all list items and all folders across the entire document library or list hierarchy.

Does changing the RowLimit solve the folder return issue?

No, the RowLimit tag only restricts the maximum number of items or folders returned in a single batch to avoid threshold errors (e.g., the 5000 item limit). The Scope attribute is what dictates whether folders or their contents are retrieved.