CAML Query to include all folders

I was working on a CAML query that retrieves all pages in a Publishing Web pages library, based on the content type. However, later on in the project, all these pages were moved into their corrosponding sub-folders. Instantly, my previously working CAML query stopped working as excepted.

The catch was, in order for a CAML query to include folders and subfolders when executing, you have to set the ‘ViewAttributes’ property to “Scope=’RecursiveAll'”. Otherwise only the root folder will be searched.

The entire CAML Query would look something like this:

The complete caml query, including the scope.

The complete caml query, including the scope.

Gotcha!