SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a way to search for folder which name starts of 'Foo' using caml query in list. How can I narrow results to return only folders?

share|improve this question

you can filter on folder content type

try this

// Source data retriever
SPSiteDataQuery query = new SPSiteDataQuery();
// Table to hold retrieved information
DataTable dt = null;

// Set data retrieve settigns
query.Lists = "<Lists BaseType='1'/>";
query.Webs = "<Webs Scope=\"Recursive\" />";
query.ViewFields = "<FieldRef Name=\"" + Fields.Title + "\" />" + "" +
"<FieldRef Name=\"Name\" />" + "" +
"<FieldRef Name=\"Fileref\" />" + "" +
"\" />";

query.Query = CamlQuery;
dt = web.GetSiteData(query);

if (dt != null)
   foreach (DataRow row in dt.Rows)
      // Do your job

And CAML query:

            <FieldRef Name='ContentType' />
            <Value Type='Computed'>Folder</Value>
            <FieldRef Name='Title' />
            <Value Type='Text'>Foo</Value>

Here is a MSDN source for content types ids.

Hope it helps,


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.