Gets the collection of all Web sites that are contained within the site collection, including the top-level site and its subsites.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)

Syntax
Visual Basic (Declaration)
Public ReadOnly Property AllWebs As SPWebCollection
Dim instance As SPSite
Dim value As SPWebCollection
value = instance.AllWebs
public SPWebCollection AllWebs { get; }
Property Value
An
SPWebCollection object that represents the Web sites.

Remarks
Best practice is to dispose explicitly of individual Web sites that are retrieved from the collection that is returned through the AllWebs property.

Example
The following code example displays in a console application the number of Web sites in a site collection and their URLs.
Dim siteCollection As New SPSite("http://" + System.Environment.MachineName)
Dim websiteCollection As SPWebCollection = siteCollection.AllWebs
Console.WriteLine("Count: {0}", websiteCollection.Count)
siteCollection.Dispose()
using(SPSite oSiteCollection = new SPSite("http://" + System.Environment.MachineName))
{
SPWebCollection collWebsites = oSiteCollection.AllWebs;
Console.WriteLine("Count: {0}", collWebsites.Count);
foreach (SPWeb oWebsite in collWebsites)
{
Console.WriteLine("Web site: {0}", oWebsite.Url);
oWebsite.Dispose();
}
}

See Also