Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

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.