SharePoint Tricks: Content By Query for Single Web

Quick little trick tonight for all you SharePoint configurators out there. Ever needed to use the Content by Query Webpart and query for justĀ a single site? Yes? Well, then you probably ‘ve noticed there is no such option when configuring the webpart… right?

Content by Query Source Options

Content by Query Source Options

Wrong! There is a way to enable single site quering, and it’s actually not that hard. First thing you have to do is export your webpart to a file. Open your .webpart file and add (or replace the old one with) this little property:

<property name="WebsOverride" type="string">&lt;Webs /;&gt;</property>

This property will, as its name suggests, override the webs property of the sitedataquery. By default the content by query webpart will fill this in with SiteCollection or Recursive. But if you don’t want this, just overwrite it with this (empty) Webs value.
After adjusting your file, upload it back to your page, and add an instance of your new webpart. And there you have it, single site goodness. ;-)

Hope it helps! Good night.

Leave a Reply