Поделиться через


SPListCollection Class

The SPListCollection class represents a collection of SPList objects.

System.Object

   Microsoft.SharePoint.SPBaseCollection

      Microsoft.SharePoint.SPListCollection

Public Methods

The following table shows the public methods of the SPListCollection class and a brief description of each.

Name Description
Add(String, String, Microsoft.SharePoint.SPListTemplate) Creates a list with the specified title, description, and list template object.
Add(String, String, Microsoft.SharePoint.SPListTemplateType) Creates a list with the specified title, description, and list definition type.
Add(String, String, Microsoft.SharePoint.SPListTemplate, SPDocTemplate) Creates a document library with the specified title, description, list template object, and document template object.
Delete Deletes the list with the specified GUID from the collection.
GetList Returns the list with the specified GUID from the collection.

Public Properties

The following table shows the public properties of the SPListCollection class, the data type of each property, and a brief description of each.

Name Data type Description
Count Int32 Gets the number of lists in the collection.
IncludeRootFolder Boolean Gets or sets a Boolean value that specifies whether the root folder of a list in the collection is returned by the RootFolder property.
Item(Int32) Microsoft.SharePoint.SPList Gets the list object at the specified index in the collection.
Item(String) Microsoft.SharePoint.SPList Gets the list object with the specified name from the collection.
Item(System.Guid) Microsoft.SharePoint.SPList Gets the list object with the specified GUID from the collection.
ListsForCurrentUser Boolean Gets or sets a Boolean value that specifies whether only lists to which the current user has permissions are returned from the collection.
Web Microsoft.SharePoint.SPWeb Gets the parent Web site of the collection.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

Use the Lists property of the SPWeb class to return an SPListCollection object that represents the collection of lists in a site, or use the Lists property of the SPList class to return an SPListCollection object that represents the collection of parent lists for a list. To create a list, use one of the Add methods represented in the previous table.

Use an indexer to return a single list from the collection. For example, assuming the collection is assigned to a variable named myLists, use myLists[index] in C#, or myLists(index) in Visual Basic .NET, where index is the index number of the list in the collection, the display name of the list, or the GUID of the list.

If users running the code have full permission for a list but do not have permissions to the site, use the GUID indexer to return a list from the collection of lists in the site. Otherwise, an Access Denied error message is returned because the user is not allowed to enumerate the collection of lists, as is done when the name indexer is used. The GUID indexer allows direct access to the item because the GUID is the primary key in the Lists table of the Microsoft Windows SharePoint Services database.

Example

The following code example iterates through all the lists of all the sites in a site collection and displays the name of the site and list in each case.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint, Microsoft.SharePoint.Utilities, and Microsoft.SharePoint.WebControls namespaces.

The example assumes the existence of an .aspx page that contains a label control.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security