Represents a collection of SPSite objects or site collections on a virtual server.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
'Declaration <SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _ <SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _ Public Class SPSiteCollection _ Inherits SPBaseCollection _ Implements ICollection 'Usage Dim instance As SPSiteCollection
Use the Sites property of the SPWebApplication class to return a collection of SPSite objects that represent all the site collections for a Web application. To create a site collection, use the Add method.
Use an indexer to return a single site object from the collection. For example, if the collection is assigned to a variable named mySites, use mySites[index] in C#, or mySites(index) in Visual Basic, where index is either the index number of the site object in the collection or the display name of the site.
The following example iterates through all site collections within the current Web application to add an item to the top-level Announcements list for each member that has been added to a group.
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