SPSiteCollection class
代表SPSite物件的集合或與特定的 Web 應用程式,包括頂層網站和其所有子網站相關聯的網站集合。每個SPSite物件或網站集合,代表內SPSiteCollection物件所組成的 Web 應用程式中的所有網站集合的集合。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.Administration.SPSiteCollection
Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class SPSiteCollection _
Inherits SPBaseCollection _
Implements IEnumerable(Of SPSite), ICollection, _
IEnumerable
'用途
Dim instance As SPSiteCollection
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class SPSiteCollection : SPBaseCollection,
IEnumerable<SPSite>, ICollection, IEnumerable
備註
使用SPWebApplication類別之Sites屬性可傳回代表 Web 應用程式的所有網站集合的SPSite物件的集合。若要建立網站集合,請使用Add方法。
若要從集合中傳回單一站台物件使用索引器。例如,若集合已指派給變數mySites,使用mySites[index]以 C# 或 Visual Basic,其中index是集合中網站物件的索引編號,或是站台的顯示名稱中的mySites(index) 。
Examples
下列範例會逐一查看目前的 Web 應用程式的每個已新增至群組的成員,將項目新增至最上層的宣告清單內的所有網站集合。
Dim webApp As SPWebApplication = SPContext.Current.Site.WebApplication
Dim siteCollections As SPSiteCollection = webApp.Sites
Dim siteCollection As SPSite
For Each siteCollection In siteCollections
Dim changes As SPChangeCollection = siteCollection.GetChanges()
Dim change As SPChange
For Each change In changes
If change.ChangeType = SPChangeType.MemberAdd Then
Dim webSite As SPWeb = siteCollection.OpenWeb()
Dim groups As SPGroupCollection = webSite.Groups
Dim list As SPList = webSite.GetList("Lists/Announcements")
Dim items As SPListItemCollection = list.Items
Dim group As SPChangeGroup = CType(change, SPChangeGroup)
Dim item As SPListItem = items.Add()
item("Title") = "User added to " +
groups.GetByID(group.Id).Name + " on " +
change.Time.ToString()
item.Update()
End If
Next change
Next siteCollection
SPWebApplication webApp = SPContext.Current.Site.WebApplication;
SPSiteCollection siteCollections = webApp.Sites;
foreach (SPSite siteCollection in siteCollections)
{
SPChangeCollection changes = siteCollection.GetChanges();
foreach (SPChange change in changes)
{
if (change.ChangeType == SPChangeType.MemberAdd)
{
SPWeb webSite = siteCollection.OpenWeb();
SPGroupCollection groups = webSite.Groups;
SPList list = webSite.GetList("Lists/Announcements");
SPListItemCollection items = list.Items;
SPChangeGroup group = (SPChangeGroup)change;
SPListItem item = items.Add();
item["Title"] = "User added to " +
groups.GetByID(group.Id).Name + " on " +
change.Time.ToString();
item.Update();
}
}
}
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.