2

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;
3

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.

  • Better late than never. – Rik Mar 2 '12 at 9:29
1

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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