SPSiteDataQuery.Lists property

Gets or sets the inner XML that specifies which lists to include in the query.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Public Property Lists As String
Dim instance As SPSiteDataQuery
Dim value As String

value = instance.Lists

instance.Lists = value
public string Lists { get; set; }

Property value

Type: System.String
An XML string that contains either an integer ID that specifies the list type, or GUIDs that specify the IDs of lists.


The top-level element in the string must be Lists.

Lists Attributes

Supported optional attributes for the Lists tag include the following:

  • ServerTemplate -- Limits the query to lists of the specified server template. By default, this attribute is not set and so the query is not limited to lists based on a particular template.

    Example: <Lists ServerTemplate="104" />

  • BaseType -- Limits the query to lists of the specified base type. By default, the query considers lists of BaseType 0 (generic lists).

    Example: <Lists BaseType="1" />

    The following table lists possible values for the attribute.




    Generic list


    Document library


    Discussion forum


    Vote or Survey


    Issues list

  • Hidden -- Determines whether the query includes hidden lists. By default, the query considers all non-hidden lists.

    Example: <Lists Hidden = "TRUE />

  • MaxListLimit -- Limits the query to the total number of lists specified. If the query would exceed the limit, the query instead fails and raises an SPException. By default, the limit is 1000. When set to 0, there is no limit to the number of lists that are considered.

    Example: <Lists MaxListLimit="500" />

Lists Subelements

Possible subelements of the Lists tag include List and WithIndex.

  • The List tag allows the query to include specific lists, instead of returning all lists of a particular type. The ID attribute identifies each list. Example:

      <List ID="7A9FDBE6-0841-430a-8D9A-53355801B5D5" />
      <List ID="3D18F506-FCA1-451e-B645-2D720DC84FD8" />
  • The WithIndex tag is an optional child of Lists and, when present, the query is limited to lists with indexed fields.


    Queries that use WithIndex will result in slow performance for a site collection with a large number of items. WithIndex is provided only for backwards compatibility, and its usage is not recommended.

    The WithIndex element has three required attributes: FieldId, Value, and Type. The Type attribute must be set to Text. In the following example, the query considers only lists that contain items whose specified field is indexed and set to the text value “Complete”.

      <WithIndex FieldId="D4819257-6B69-41F1-82C8-A91615BFF500" Type="Text" Value="Complete" />


The following example is a console application that retrieves data from all lists that are based on the Contacts list template.

Imports System
Imports System.Data
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")
         Using web As SPWeb = site.OpenWeb()

            Dim query As SPSiteDataQuery = New SPSiteDataQuery()

            ' Query all Web sites in this site collection.
            query.Webs = "<Webs Scope='SiteCollection'>"

            ' Ask for all lists created from the contacts template.
            query.Lists = "<Lists ServerTemplate='105' />"

            ' Get the Title (Last Name) and FirstName fields.
            query.ViewFields = "<FieldRef Name='Title' />"
            query.ViewFields += "<FieldRef Name='FirstName' Nullable='TRUE'/>"

            Dim results As DataTable = web.GetSiteData(query)

            For Each row As DataRow In results.Rows
               Console.WriteLine("{0} {1}", row("FirstName"), row("Title"))

         End Using
      End Using
   End Sub
End Module
using System;
using System.Data;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite site = new SPSite("https://localhost"))
            using (SPWeb web = site.OpenWeb())
               SPSiteDataQuery query = new SPSiteDataQuery();

               // Query all Web sites in this site collection.
               query.Webs = "<Webs Scope=\"SiteCollection\">";

               //Ask for all lists created from the contacts template.
               query.Lists = "<Lists ServerTemplate=\"105\" />";

               // Get the Title (Last Name) and FirstName fields.
               query.ViewFields = "<FieldRef Name=\"Title\" />"; 
               query.ViewFields += "<FieldRef Name=\"FirstName\" Nullable=\"TRUE\"/>";

               DataTable results = web.GetSiteData(query);

               foreach (DataRow row in results.Rows)
                  Console.WriteLine("{0} {1}", row["FirstName"], row["Title"]);

See also


SPSiteDataQuery class

SPSiteDataQuery members

Microsoft.SharePoint namespace