Compartir a través de


de la propiedad SPSiteDataQuery.Webs

Obtiene o establece el XML interno que especifica los sitios Web que desea incluir en la consulta. según lo especificado por el atributo Scope en la etiqueta de Webs en la consulta. De forma predeterminada, la consulta considera que el sitio Web actual, es decir, el sitio Web desde la que la

Espacio de nombres:  Microsoft.SharePoint
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
Public Property Webs As String
    Get
    Set
'Uso
Dim instance As SPSiteDataQuery
Dim value As String

value = instance.Webs

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

Valor de propiedad

Tipo: System.String
Una cadena que contiene el XML interno que especifica los sitios Web para incluir.

Comentarios

La propiedad Webs especifica los sitios Web que desea incluir en la consulta. De forma predeterminada, la consulta considera sólo el sitio Web desde el que se invocó el método GetSiteData .

Puede ampliar el alcance de la consulta estableciendo la propiedad Webs en una cadena que contiene una etiqueta de Webs y un atributo Scope . Los posibles valores del atributo Scope incluyen Recursive y SiteCollection.

<Webs Scope="Recursive" />

<Webs Scope="SiteCollection" />

Cuando se establece el atributo Scope en Recursive, la consulta tiene en cuenta el actual sitio Web y todos los subsitios del sitio Web actual.

Cuando se establece el atributo Scope en SiteCollection, la consulta considera todos los sitios Web que se encuentran en la misma colección de sitios que el sitio Web actual. De los valores de atributo de dos, se trata más globales.

Ejemplos

En el siguiente ejemplo es una aplicación de consola que se recupera información sobre el tamaño de cada archivo en cada biblioteca de documentos en una colección de sitios. La aplicación recorre en iteración los datos e imprime los totales en la biblioteca, sitio Web y los niveles de colección de sitios.

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 document libraries.
            query.Lists = "<Lists BaseType='1' />"

            ' Get IDs for fields used in the query.
            Dim fileSizeId As String = SPBuiltInFieldId.File_x0020_Size.ToString("B")
            Dim fileSizeDisplayId As String = SPBuiltInFieldId.FileSizeDisplay.ToString("B")

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

            ' Specify the view fields.
            query.ViewFields = "<FieldRef Name='" + fileSizeDisplayId + "' />"
            query.ViewFields += "<ProjectProperty Name='Title' />"
            query.ViewFields += "<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, webTotal, grandTotal As Long

            For Each row As DataRow In results.Rows

               Dim curWeb As String = CType(row("ProjectProperty.Title"), String)
               Dim curList As String = CType(row("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(row(fileSizeDisplayId))

               ' 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.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
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 document libraries.
               query.Lists = "<Lists BaseType=\"1\" />";

               // Get IDs for fields used in the query.
               string fileSizeId = SPBuiltInFieldId.File_x0020_Size.ToString("B");
               string fileSizeDisplayId = SPBuiltInFieldId.FileSizeDisplay.ToString("B");

               // Select the records.
               query.Query = "<Where><Gt>";
               query.Query += "<FieldRef ID=\"" + fileSizeId + "\" />";
               query.Query += "<Value Type=\"Number\">0</Value>";
               query.Query += "</Gt></Where>";

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

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

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

               foreach (DataRow row in results.Rows)
               {
                  string curWeb = row["ProjectProperty.Title"] as string;
                  string curList = row["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(row[fileSizeDisplayId]);

                  // 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.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;
      }
   }
}

Vea también

Referencia

clase SPSiteDataQuery

Miembros SPSiteDataQuery

Espacio de nombres Microsoft.SharePoint