Represents a collection of sites in a Web application, including a top-level Web site and all its subsites.
Definition:
Represents a collection of sites in a Web application, including a top-level Web 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 in the Web application.
More reading:
Code example:
//providing an absolute URL,
SPSite mySiteCollection = new SPSite("http://mysharepointsite/");
//using the current context
SPSite mySiteCollection = SPContext.Current.Site;
SPSite
implements the IDisposable
interface so you should close the object when you no longer need it. This is not the case when you're object is assigned with the Context
. So in the second line, the Dispose()
should not be called. You can close it manually or use the using statement to do this for you:
//manually
mySiteCollection.Dispose();
//using statement
using (SPSite mySiteCollection = new SPSite("http://mysharepointsite/")
{
//your code here
}