title: CAML query that includes folders in result set
body: <p>I'm trying to write a CAML query that executes against a specific SPList, scoped to a specific folder, recursive from that point, and returns all ListItems (which meet a criteria) and Folders.</p>
  
  <p>Here's the code for the query which seems like it should work (formatted for readability):</p>
  
  <pre><code>SPQuery query = new SPQuery();
  query.Query = "
  &lt;Where&gt;
      &lt;Or&gt;
          &lt;Contains&gt;
              &lt;FieldRef Name=\"FileRef\" /&gt;
              &lt;Value Type=\"Text\"&gt;foo&lt;/Value&gt;
          &lt;/Contains&gt;
          &lt;Eq&gt;
              &lt;FieldRef Name=\"FSObjType\" /&gt;
              &lt;Value Type=\"Lookup\"&gt;1&lt;/Value&gt;
          &lt;/Eq&gt;
      &lt;/Or&gt;
  &lt;/Where&gt;";
  
  query.ViewFields = "
  &lt;FieldRef Name=\"CustomField1\" Nullable=\"TRUE\" /&gt;
  &lt;FieldRef Name=\"CustomField2\" Nullable=\"TRUE\" /&gt;
  &lt;FieldRef Name=\"CustomField3\" Nullable=\"TRUE\" /&gt;
  ";
  
  query.RowLimit = 500;
  query.ViewAttributes = "Scope=\"RecursiveAll\"";
  query.Folder = startingFolder;
  DataTable dt = myList.GetItems(query).GetDataTable();
  </code></pre>
  
  <p>So - this only returns the ListItems - no folders.</p>
  
  <p>If I remove the other conditions from the query, only leaving the <code>FSObjType=1</code>, I get a COM exception "Cannot complete this action. Please try again."</p>
  
  <p>If I then remove the ViewFields, leaving only the <code>Scope=RecursiveAll</code> and <code>FSObjType=1</code>, I get an empty result set back.</p>