1

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?

1 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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