Saturday, October 17, 2009

Iterating SharePoint sites using a search query

This is a pretty simple query that can be used to iterate the sites and sub-sites under some URL and get the sites’ title, description and URL:

SELECT url, contentclass, title, description FROM scope() WHERE (contentclass='STS_Web' OR contentclass='STS_Site') and site='http://myserver/mysite'

The contentclass managed field is used to filter the “site” search items and the site managed field – to specify a starting URL the sites below which we want to retrieve. Normally the STS_Web and STS_Site items cause issues since they “hide” the welcome pages of the corresponding sites but in this case they come quite handy allowing the retrieval of some metadata (title and description) of the sites.

No comments:

Post a Comment