SPQuery and SPSiteDataQuery in SharePoint

Before reading this blog, you may also like to know about CAML Query. You can know about CAML Query in details.

In this blog, we will see SPQuery and SPSiteDataQuery.

SPQuery and SPSiteDataQuery in SharePoint 2010
SPQuery – SPQuery can be used to query a single list.
SPQuery query = new SPQuery();

SPSiteDataQuery – It allows you to query from multiple lists whether it can be from a single-site or from that site and from sub sites.

SPSiteDataQuery query = new SPSiteDataQuery();

Both SPQuery and SPSiteDataQuery have Query property which accepts CAML query text.
For SPSiteDataQuery you may specify a scope. SPSiteDataQuery object has a property “Webs
which defines the scope.

This property is described as “It specifies which web sites to include in the query as specified the scope attribute on the Webs tag in the query. By default, the query considers the current web site.”

Like SPQuery you may put Row Limit in SPSiteDataQuery.

To know more about CAML Query, please visit my another blog post Learn CAML Query step by Step

CAML Query in SharePoint 2010

1 thought on “SPQuery and SPSiteDataQuery in SharePoint”

Leave a Comment