How to query all lists that use a certain content type in SharePoint?
I have the following CAML query:
<Where>
<And>
<Eq>
<FieldRef Name=开发者_运维技巧'PublishToSM' />
<Value Type='Boolean'>True</Value>
</Eq>
<IsNull>
<FieldRef Name='SMUpdateDate' />
</IsNull>
</And>
</Where>
I have only one content type that uses these fields. When I run this query against a list that uses this content type everything works fine. When I run it against a List that does not it throws the error: One or more field types are not installed properly. Go to the list settings page to delete these fields.
I would like to be able to search all Lists on all websites in a site collection. Can this be done without erroring out?
Use SPSiteDataQuery, add a where clause to include the content type. i.e.:
<Where>
<And>
<Eq>
<FieldRef Name='ContentType' />
<Value Type='Text'>CONTENTTYPE NAME</Value>
</Eq>
<And>
<Eq>
<FieldRef Name='PublishToSM' />
<Value Type='Boolean'>True</Value>
</Eq>
<IsNull>
<FieldRef Name='SMUpdateDate' />
</IsNull>
</And>
</And>
</Where>
<BeginsWith>
<FieldRef Name='ContentTypeId' />
<Value Type='ContentTypeId'>CONTENTTYPE ID</Value>
</BeginsWith>
Set the SPSiteDataQuery
's Scope
property to SiteCollection. By setting the Lists
property you can also limit the search to for instance document libraries etc. The ViewFields
property can be set to limit the fields retrieved (i.e. instead of the equivalent of a select *
on the items's fields)
精彩评论