views:

2766

answers:

2

It seems like searching with CAML and SPQuery doesn't work properly against custom metadata, when searching for SPFolders instead of files, or when searching for custom content types. I've been using U2U to test a variety of queries, and just not getting anywhere. The doc's aren't very complete on the topic, and google isn't helping either.

In one test, I'm trying to locate any SPFolders in the tree that are a specific custom content-type. If I understand CAML correctly, this should work:

<Query>
    <Where>
        <Eq>
            <FieldRef Name='ContentType' />
            <Value Type='Text'>CustomTypeName</Value>
        </Eq>
    </Where>
</Query>

In another test, I'm trying to locate any SPFolder that has a custom metadata property set to a specific value.

<Query>
    <Where>
        <Eq>
            <FieldRef Name='CustomProp' />
            <Value Type='Text'>SpecificPropValue</Value>
        </Eq>
    </Where>
</Query>

In both cases, I'm setting the root for the search to a document library that contains folders, which contain folders, which contain folders (phew.) Also, I'm setting the SPQuery to search recursively.

The folder I'm searching for a two steps down are the farthest down in the tree. I don't want to iterate all the way in to manually locate the folders in question.

EDIT It might also be helpful to know that I'm using both SPList.GetItems with an SPQuery as an argument, and SPWeb.GetSiteData with an SPSiteDataQuery as an argument. At the moment it appears that folders aren't included in the search-set for either of these queries.

Any help would be greatly appreciated.

+1  A: 

Try adding SharePoint Manager and Stramit CAML Viewer to your toolset.

I have found both to be very important for figuring out CAML problems.

Nat
+2  A: 

After more research, I'm answering my own question.

Apparently the methods that I'm using to query don't return SPFolders as items in the result set. Only list items are returned, basically just documents.

My fix was to execute a CAML query for all the documents with a certain metadata tag/value, and then using the parent folder of the first one as the representative folder for the set. Works well enough for my needs.

David Hill