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 trying to use CrossListQueryInfo to query all Pages Libraries (ServerTemplate 850) across the site collection for a particular custom content type. However, specifying the content type in the query returns no results.

If I leave out the content type clause, results do come back, so the problem probably doesn't lie in the ViewFields.

I suspect my Content Type is broken somehow (filtering on another custom content type works perfectly) but I have no idea where to start.

Query:

<Where>
  <Eq>
    <FieldRef Name='ContentType' />
    <Value Type='Text'>Custom News Article</Value>
  </Eq>
</Where>
<OrderBy>
  <FieldRef Name=\"ArticleStartDate\" Ascending=\"FALSE\"></FieldRef>
</OrderBy>

Code:

CrossListQueryInfo query1 = new CrossListQueryInfo();
query1.Query = clause.ToString(); // See above

if (rowLimit > 0) query1.RowLimit = rowLimit;
query1.ViewFields = viewFields;
query1.Lists = string.Format("<Lists ServerTemplate=\"850\" />");
query1.Webs = "<Webs Scope=\"SiteCollection\" />";
query1.WebUrl = SPContext.Current.Site.RootWeb.ServerRelativeUrl;
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Maybe late, but the fix is to change <Eq> for <BeginsWith>, using the ContentTypeId. The contenttype of the list item is actually a CHILD of the content type you are searching for.

share|improve this answer
    
Better late than never. –  Rik Mar 2 '12 at 9:29
add comment

Try switching your search from a site collection scope to a a recursive search(i.e. Webs Scope="Recursive").

share|improve this answer
add comment

I have not done extensive research on this, but I have had similar experiences...

I have not yet found the ultimate answer to this but here are a couple of things you can try:

<Where><Eq><FieldRef Name='ContentTypeId' /><Value Type='Text'>123...</Value></Eq></Where>

Or

<Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>MyPageType</Value></Eq></Where>

I have basically been trying out different things untill I got results, and from glancing over my code, these are the ones which are left in the codebase :)

My queries have usually been combined with other conditions involving 'TaxCatchAll' so your mileage may vary.

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.