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:

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

Here is a MSDN source for content types ids.

Hope it helps,

Andrew

share|improve this answer

Your Answer

 
discard

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.