Reputation: 103
I want to filter from the CAML query to ListItem.ContentType.Hidden.
with SharePoint To Linq like this Code.
var query = from item in list.GetItems(CamlQuery.CreateAllItemsQuery())
where item.ContentType.Hidden == false select item;
If I check with pure CAML Query,Should I write code and how?
Is a simple question.
Thank you.
Upvotes: 1
Views: 2219
Reputation: 14880
You cannot check the Hidden
property in a pure CAML query. In CAML only the ContentType's name and the ID is available (Fields ContentType and ContentTypeID).
If there are only a few hidden content types that have to be excluded you could first load these hidden content types and exclude them in the CAML query:
Extract hidden content types:
SPWeb web = // ...
IEnumerable<string> contentTypeIds = web.AvailableContentTypes
.Cast<SPContentType>()
.Where(ct => ct.Hidden)
.Select(ct => ct.Id.ToString());
CAML query:
<Where>
<And>
<Neq>
<FieldRef Name='ContentTypeID'/>
<Value Type='Text'>[HiddenContentTypeId]</Value>
</Neq>
<Neq>
<FieldRef Name='ContentTypeID'/>
<Value Type='Text'>[AnotherHiddenContentTypeId]</Value>
</Neq>
</And>
<!-- more hidden content types -->
</Where>
Upvotes: 4