SPSite.AllWebs property
取得包含在網站集合,包括最上層的網站及子網站內的所有網站集合。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public ReadOnly Property AllWebs As SPWebCollection
Get
'用途
Dim instance As SPSite
Dim value As SPWebCollection
value = instance.AllWebs
public SPWebCollection AllWebs { get; }
Property value
Type: Microsoft.SharePoint.SPWebCollection
SPWebCollection 物件,表示 Web 站台。
備註
最佳作法是明確處置透過AllWebs屬性會傳回集合中擷取的個別網站。
Examples
下列程式碼範例顯示在主控台應用程式在網站集合和其 Url 的網站數目。
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();
}
}
注意事項 |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |