Condividi tramite


SPWeb.GetListsOfType Method

Gets the lists of the specified type.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Function GetListsOfType ( _
    baseType As SPBaseType _
) As SPListCollection
'Usage
Dim instance As SPWeb
Dim baseType As SPBaseType
Dim returnValue As SPListCollection

returnValue = instance.GetListsOfType(baseType)
public SPListCollection GetListsOfType(
    SPBaseType baseType
)

Parameters

Return Value

Type: Microsoft.SharePoint.SPListCollection
The lists with the specified base list type.

Remarks

Use this method to query a collection of lists of the specified base list type from the website.

Examples

The following example is a console application that gets the document libraries on a website, iterates through the lists, and prints each list title to the console.

Imports System
Imports Microsoft.SharePoint

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

            Dim lists As SPListCollection = web.GetListsOfType(SPBaseType.DocumentLibrary)

            For Each list As SPList In lists
               Console.WriteLine(list.Title)
            Next

         End Using
      End Using
      Console.ReadLine()
   End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               SPListCollection lists = web.GetListsOfType(SPBaseType.DocumentLibrary);

               foreach (SPList list in lists)
               {
                  Console.WriteLine(list.Title);
               }
            }
         }
         Console.ReadLine();
      }
   }
}

See Also

Reference

SPWeb Class

SPWeb Members

Microsoft.SharePoint Namespace