SPSiteCollection 类
代表SPSite对象的集合或与特定的 Web 应用程序,包括首要网站和所有子网站关联的网站集。每个SPSite对象或网站集内SPSiteCollection对象包含的 Web 应用程序中的所有网站集的集合,这些对象表示。
继承层次结构
System.Object
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.Administration.SPSiteCollection
命名空间: Microsoft.SharePoint.Administration
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
<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的变量中,使用 C# 中的mySites[index]或mySites(index)在 Visual Basic 中,其中index是集合中的网站对象的索引号,或者该站点的显示名称。
示例
下面的示例循环访问当前的 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();
}
}
}
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。