Using the Content Query Web Part
The ContentByQueryWebPart, commonly referred to as the Content Query Web Part, is a part of the Enterprise Content Management (ECM) functionality in Microsoft Office SharePoint Server. It aggregates and displays list items within a site hierarchy. In addition to hierarchical query capabilities, the Content Query Web Part provides caching and query optimization for the SPSiteDataQuery object that it contains. These optimizations have better performance than if you directly call methods of the SPSiteDataQuery object. You can also use SharePoint Designer to customize the aggregation and display capabilities of the Content Query Web Part with little or no coding. For more information, see ContentByQueryWebPart Class and the following procedures on MSDN:
- How to: Customize the Content Query Web Part by using Custom Properties.
- How to: Customize XSL for the Content Query Web Part.
- How to: Display Custom Fields in a Content Query Web Part.
- How to: Customize RSS for the Content Query Web Part.
The Content Query Web Part has the following limitations:
- You can only aggregate data within a single site collection.
- You can only aggregate list information.
Alternatively, you can use the Content Query Web Part's underlying CrossListQueryInfo and CrossListQueryCache classes to retrieve list information programmatically. However, the recommended approach for a programmatic query is to use the PortalSiteMapProvider class. This class offers additional features that the Content Query Web Part does not have. For more information, see Using the PortalSiteMapProvider on MSDN.
|The Content Query Web Part is only supported in publishing sites. Also, the site collection that contains the site must have the publishing features enabled. In any other context, the results may be inconsistent. For example, RSS feeds will not be correctly queried.|
Another option is to use SharePoint search. This is appropriate when you must retrieve large result sets and can accept some data latency. For more information, see Using Search to Aggregate Data.