Alex Rivera | Logout

CAML queries: how to filter folders from result set?

Asked 2008-12-02T08:22:20.210
23

I'm using caml query to select all documents which were modified or added by user. Query runs recursively on all subsites of specified site collection.

Now problem is I can't get rid of folders which are also part of result set. For now I'm filtering them from result datatable. But I'm wondering: Is it possible to filter out folders from result set just by using caml?

Edit
Report

2 Answers

13

So, i figured it out :) You can use FieldRef='ContentType' in your caml query and specify typr of content type which you want to select or exclude from select.

So in my case I've added this condition to my caml expression:

<Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq>

NOTE: There are problems in multi language setup. Name of content type can be different, so it is good to get names of content types from resources

UPDATE:

It looks like I was too quick in my assumptions. I need to filter out all contett types based on folder content type, because in our projects such content types are used :(

I was not able to create workable query in caml, so I added view field element to my query which selects ContentTypeId of list item and I filter-out rows which are based on folder content type.

Code to do this is trivial, but it bothers me that such simple task cannot be done by pure caml.

answered 2008-12-02T10:35:59.630
0

Check my other answer CAML query that includes folders in result set

Simply changing the operators might get you what you need

<Where>
  <NotIncludes>
    <FieldRef Name='ContentTypeId' />
    <Value Type='ContentTypeId'>0x0120</Value>
  </NotIncludes>
</Where>

I'm not sure if that'll work.

answered 2011-12-22T16:04:12.977

Your Answer