SPWebCollection Class

Represents a collection of SPWeb objects.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPWebCollection

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

Syntax

'Declaration
<SubsetCallableTypeAttribute> _
<ClientCallableTypeAttribute(Name := "WebCollection", CollectionChildItemType := GetType(SPWeb),  _
    ServerTypeId := "{c197d59e-d070-43bf-ad5e-10d6152e38a6}", OnChildItemEnumerated := "{1}.Dispose();")> _
Public Class SPWebCollection _
    Inherits SPBaseCollection _
    Implements IEnumerable(Of SPWeb), IEnumerable
'Usage
Dim instance As SPWebCollection
[SubsetCallableTypeAttribute]
[ClientCallableTypeAttribute(Name = "WebCollection", CollectionChildItemType = typeof(SPWeb), 
    ServerTypeId = "{c197d59e-d070-43bf-ad5e-10d6152e38a6}", OnChildItemEnumerated = "{1}.Dispose();")]
public class SPWebCollection : SPBaseCollection, 
    IEnumerable<SPWeb>, IEnumerable

Remarks

Use the Webs property of the SPWeb class to return all the subsites beneath a site, the AllWebs property of the SPSite class to return all sites within the site collection, or one of the GetSubwebsForCurrentUser methods of the SPWeb class to return all the subsites for the current user.

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

Thread Safety

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

See Also

Reference

SPWebCollection Members

Microsoft.SharePoint Namespace