This documentation is archived and is not being maintained.

SPSiteDataQuery.Lists Property

Windows SharePoint Services 3

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

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. Example: <Lists ServerTemplate="104" />

  • BaseType -- Limits the query to lists of the specified base type. Example: <Lists BaseType="1" />

    The following table lists possible values for the default base types.




    Generic list


    Document library


    Discussion forum


    Vote or Survey


    Issues list

  • Hidden -- Determines whether the query will include hidden lists. Example: <Lists Hidden = "TRUE />

    By default, the query will consider all non-hidden lists of base type 0.

  • MaxListLimit -- Limits the query to the total number of lists specified. If the query would exceed the limit, the query will instead fail and raise an SPException. By default, the limit is 1000. When set to 0, there is no limit to the number of lists that will be 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 will be limited to lists with indexed fields. 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 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 information about the size of every file in every document library in a site collection. The application then iterates through the data and prints totals at the library, Web site, and site collection levels.

Imports System
Imports System.Data
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("http://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 document libraries.
            query.Lists = "<Lists ServerTemplate='101' />"

            ' Select the records.
            query.Query = "<Where>" + _
                             "<Gt>" + _
                               "<FieldRef Name='File_x0020_Size' />" + _
                               "<Value Type='Number'>0</Value>" + _
                             "</Gt>" + _

            ' Specify the fields.
            query.ViewFields = "<FieldRef Name='FileSizeDisplay' />" + _
                               "<ProjectProperty Name='Title' />" + _
                               "<ListProperty Name='Title' />"

            ' Submit the query.
            Dim results As DataTable = web.GetSiteData(query)

            ' Process the results.
            Dim webTitle As String = String.Empty
            Dim listTitle As String = String.Empty
            Dim listTotal As Long = 0
            Dim webTotal As Long = 0
            Dim grandTotal As Long = 0

            Dim i As Integer
            For i = 0 To results.Rows.Count - 1 Step i + 1

               Dim curRow As DataRow = results.Rows(i)
               Dim curWeb As String = CType(curRow("ProjectProperty.Title"), String)
               Dim curList As String = CType(curRow("ListProperty.Title"), String)

               If webTitle <> curWeb Then
                  listTotal = PrintSubTotal(listTotal, listTitle)
                  listTitle = String.Empty

                  webTotal = PrintSubTotal(webTotal, webTitle)
                  webTitle = curWeb

                  Console.WriteLine(vbCrLf + "Web site: {0}", webTitle)
               End If

               If listTitle <> curList Then
                  listTotal = PrintSubTotal(listTotal, listTitle)
                  listTitle = curList
               End If

               ' Get the size of the current file.
               Dim fileSize As Integer = Convert.ToInt32(results.Rows(i)("FileSizeDisplay"))

               ' Add it to the totals.
               listTotal += fileSize
               webTotal += fileSize
               grandTotal += fileSize


            listTotal = PrintSubTotal(listTotal, listTitle)
            webTotal = PrintSubTotal(webTotal, webTitle)
            Console.WriteLine(vbCrLf + "Grand total: {0}", grandTotal)

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
   End Sub

   Function PrintSubTotal(ByVal total As Long, ByVal name As String) As Long
      If total <> 0 Then
         Console.WriteLine("  Total file size for {0} is {1}.", name, total)
      End If
      Return 0
   End Function

End Module