Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
 Lists Property

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPSiteDataQuery.Lists Property (Microsoft.SharePoint)
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)
Visual Basic (Declaration)
Public Property Lists As String
Visual Basic (Usage)
Dim instance As SPSiteDataQuery
Dim value As String

value = instance.Lists

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

Property Value

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.

    Value

    Description

    0

    Generic list

    1

    Document library

    3

    Discussion forum

    4

    Vote or Survey

    5

    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:

    Xml
    <Lists>
      <List ID="7A9FDBE6-0841-430a-8D9A-53355801B5D5" />
      <List ID="3D18F506-FCA1-451e-B645-2D720DC84FD8" />
    </Lists>
    
  • 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”.

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

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.

Visual Basic
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>" + _
                          "</Where>"

            ' 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

            Next

            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...")
      Console.ReadLine()
   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
C#
using System;
using System.Data;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("http://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 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>" +
                             "</Where>";

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

               // Submit the query.
               DataTable results = web.GetSiteData(query);

               // Process the results.
               string webTitle = string.Empty;
               string listTitle = string.Empty;
               long listTotal = 0;
               long webTotal = 0;
               long grandTotal = 0;

               for (int i = 0; i < results.Rows.Count; i++)
               {
                  DataRow curRow = results.Rows[i];
                  string curWeb = curRow["ProjectProperty.Title"] as string;
                  string curList = curRow["ListProperty.Title"] as string;

                  if (webTitle != curWeb)
                  {
                     listTotal = PrintSubTotal(listTotal, listTitle);
                     listTitle = string.Empty;

                     webTotal = PrintSubTotal(webTotal, webTitle);
                     webTitle = curWeb;

                     Console.WriteLine("\nWeb site: {0}", webTitle);
                  }

                  if (listTitle != curList)
                  {
                     listTotal = PrintSubTotal(listTotal, listTitle);
                     listTitle = curList;
                  }

                  // Get the size of the current file.
                  int fileSize = 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("\nGrand total: {0}", grandTotal);

            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }

      private static long PrintSubTotal(long total, string name)
      {
         if (total != 0)
            Console.WriteLine("  Total file size for {0} is {1}.", name, total);
         return 0;
      }
   }
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Multiple specific lists does not work      Michel Capdevila   |   Edit   |   Show History

Does not work if you set the List ID like the sample

<Lists>
<List ID="7A9FDBE6-0841-430a-8D9A-53355801B5D5" />
<List ID="3D18F506-FCA1-451e-B645-2D720DC84FD8" />
</Lists>

Perhaps if lists are same type, not tested.

Tags What's this?: Add a tag
Flag as ContentBug
Fix for multiple specific lists      Gautam Shetty ... Noelle Mallory - MSFT   |   Edit   |   Show History

The documentation for Lists is wrong.

The List subelement needs to be set in the form:

<List ID="7A9FDBE6-0841-430a-8D9A-53355801B5D5" />
<List ID="3D18F506-FCA1-451e-B645-2D720DC84FD8" />

without the outer Lists node.

SameName SiteColumn for Multiple List using in SPSiteDataQuery      Saurabh_ClearDevelop   |   Edit   |   Show History

I am trying to use Multiple Lists in SPSiteDataQuery and each list has SiteColumn Name "ID" (which is by default in SPList). Now i want to make query and create Filter on "ID" field.........how does SPSiteDataQuery knows "ID" of which List i m using....??

SPSiteDataQuery dQuery = new SPSiteDataQuery();
dQuery.Lists = "<Lists><ListID=" + List1.ID + "/><ListID=" + List2.ID + "/><ListID=" + List3.ID + "/><ListID=" + List4.ID + "/><ListID=" + List5.ID + "/></Lists>";

dQuery.Query = @"<Where>" +
"<Gt>" +
"<FieldRef Name=\"ID\"/>" +
"<Value Type=\"Counter\">0</Value>" +
"</Gt>" +
"</Where>";

how does it know the "ID" m using is of List1,List2,List3,List4 or List5.....???

Tags What's this?: Add a tag
Flag as ContentBug
Multiple ListIds with different BaseTypes      irfan malik   |   Edit   |   Show History
If you specified multiple ListId in the query and there is no BaseType or ServerTemplateType, SharePoint will enforce the query on one BaseType.
So if the multiple ListIds contain mixed BaseType, then only one of the BaseTypes will be used and all the other lists with different BaseType will be skipped.

By default BaseType =0 (Generic List) will be used.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker