Share via


SPSite Class

The SPSite class represents a collection of sites on a virtual server, including a top-level site and all its subsites. Each SPSite object, or site collection, is represented within an SPSiteCollection object that consists of the collection of all site collections on the virtual server.

System.Object

   Microsoft.SharePoint.SPSite

Public Constructors

The following table shows the public constructors of the SPSite class and a brief description of each.

Name Description
SPSite(String) Initializes a new instance of the SPSite class based on the specified absolute URL.
SPSite(Guid) Initializes a new instance of the SPSite class based on the specified GUID for a site collection.

Public Fields

The following table shows the public fields of the SPSite class and a brief description of each.

Name Description
MaxFullUrlLength Represents the maximum number of characters used in the absolute URL for a site collection.
MaxWebNameLength Represents the maximum number of characters that can be used in site names for the site collection.

Public Methods

The following table shows the public methods of the SPSite class and a brief description of each.

Name Description
Close Closes the site collection and releases resources.
ConfirmUsage Returns a Boolean value that certifies whether the site collection is in use.
Delete() Deletes the site collection from the server.
Delete(Boolean) Deletes the site collection from the server and removes the site collection users from the Active Directory directory service if bDeleteADAccounts is true.
Dispose Releases all unmanaged resources used by the site collection object.
GetCatalog Returns the list template gallery, site template gallery, or Web Part gallery for the site collection.
GetCustomListTemplates Returns the collection of list templates for the specified site.
GetCustomWebTemplates Returns the collection of site templates for the site collection based on the specified locale ID (LCID).
GetSelfServiceSiteCreationSettings Returns the settings used for Self-Service Site Creation.
GetWebTemplates Returns the collection of site definitions available for creating sites within the site collection.
MakeFullUrl Returns the absolute URL for the specified server-relative URL.
OpenWeb() Returns the site associated with the URL used in the SPSite constructor.
OpenWeb(String) Returns the site located at the specified server-relative or site-relative URL.
OpenWeb(Guid) Returns the site with the specified GUID.
SelfServiceCreateSite(String, String, String, UInt32, String, String, String, String, String, String, String) Creates a site collection by using Self-Service Site Creation.
SelfServiceCreateSite(String, String, String, UInt32, String, String, String, String, String, String, String, String) Creates a site collection by using Self-Service Site Creation based on the specified quota template and other information.
StorageManagementInformation Returns information about storage management for the site collection.

Public Properties

The following table shows the public properties of the SPSite class, the data type of each property, and a brief description of each.

Name Data Type Description
AllowUnsafeUpdates Boolean Gets or sets a Boolean value that specifies whether to allow updates to the database as a result of a GET request or without requiring a security validation.
AllWebs Microsoft.SharePoint.SPWebCollection Gets the collection of all Web sites contained within the site collection, including the top-level site and nested subsites.
CatchAccessDeniedException Boolean Gets or sets a Boolean value that specifies whether to handle access denied exceptions and require user authentication.
CertificationDate System.DateTime Gets the date on which usage was checked for the site collection.
DeadWebNotificationCount Int16 Gets the number of notifications that are sent regarding Web sites within the site collection that are out of use.
GlobalPermMask Microsoft.SharePoint.SPRights Gets or sets the rights for the permissions mask that is used globally on the virtual server.
HostName String Gets the name of the server that hosts the site collection.
ID System.Guid Gets the GUID that identifies the site collection.
IISAllowsAnonymous Boolean Gets a Boolean value that indicates whether anonymous access is enabled in Internet Information Services (IIS).
LastContentModifiedDate System.DateTime Gets the date and time in Coordinated Universal Time (UTC) when the content of the site was last changed.
LastSecurityModifiedDate System.DateTime Gets the date and time in Coordinated Universal Time (UTC) when security on the site was last changed.
LockIssue String Gets or sets the explanation used in locking a site collection.
Owner Microsoft.SharePoint.SPUser Gets or sets the owner of the site collection.
Port Int32 Gets the port number used for input and output on the virtual server containing the site collection.
PortalName String Gets or sets the name of a portal.
PortalUrl String Gets or sets the URL to a portal.
Protocol String Gets the protocol, HTTP or HTTPS, that is used by the server.
Quota Microsoft.SharePoint.Administration.SPQuota Gets or sets a quota for the site collection.
ReadLocked Boolean Gets or sets a Boolean value that indicates whether the site collection is locked and unavailabe for Read access.
RootWeb Microsoft.SharePoint.SPWeb Gets the top-level Web site of the site collection.
SecondaryContact Microsoft.SharePoint.SPUser Gets or sets the secondary contact used for the site collection.
ServerRelativeUrl String Gets the server-relative URL of the top-level Web site in the site collection.
Url String Gets the full URL to the top-level Web site of the site collection, including host name, port number, and path.
Usage Microsoft.SharePoint.SPSite.UsageInfo Gets information about site usage, including bandwidth, storage, and number of visits to the site collection.
WarningNotificationSent Boolean Gets a Boolean value that indicates whether a warning notification was sent.
WriteLocked Boolean Gets or sets a Boolean value that indicates whether the site collection is locked and unavailabe for Write access.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

To instantiate an SPSite object for a specific site collection on an ASP.NET page, or for a specific site collection within a console application, use the SPSite constructor as follows:

SPSite mySite = new SPSite("Absolute_URL");

Within an ASP.NET application, use the GetContextSite method of the SPControl class to return an SPSite object that represents the current site, as follows:

SPSite mySite = SPControl.GetContextSite(Context);

Use the Sites property of the SPVirtualServer class to return an SPSiteCollection object that represents the collection of site collections on a virtual server. Use an indexer to return a single site collection 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 .NET, where index is either the index number of the site in the collection or the display name of the site.

If you create your own SPSite object, you can use the Dispose method or the Close method to close the object. However, if you have a reference to a shared resource, such as when the object is provided by the GetContextSite method in a Web Part, do not use either method to close the object. In scenarios where you have a reference to a shared resource, instead let Windows SharePoint Services or your portal application manage the object. Using either method on a shared resource causes an access violation error to occur.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security