Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

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 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.

    Value

    Description

    0

    Generic list

    1

    Document library

    3

    Discussion forum

    4

    Vote or Survey

    5

    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:

    <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 is limited to lists with indexed fields.

    Caution noteCaution

    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”.

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

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

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 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"]);
            }
         }
         Console.ReadLine();
      }
   }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.