SPSite.AllWebs Property
Windows SharePoint Services 3
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)
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
The following code example displays in a console application the number of Web sites in a site collection and their URLs.
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(); } }
Note: |
|---|
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects. |
Note: