Export (0) Print
Expand All
Expand Minimize

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

public SPListCollection GetListsOfType(
	SPBaseType baseType
)

Parameters

baseType
Type: Microsoft.SharePoint.SPBaseType

The list type.

Return Value

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

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

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.

using System;
using Microsoft.SharePoint;

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

               foreach (SPList list in lists)
               {
                  Console.WriteLine(list.Title);
               }
            }
         }
         Console.ReadLine();
      }
   }
}
Show:
© 2014 Microsoft