SPSite Class / SPSite.Features

Represents a collection of sites in a Web application, including a top-level Web site and all its subsites.

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 oSiteCollection = new SPSite(“Absolute_URL”);

Within an ASP.NET application, you can use the Site property of the SPContext class to return an SPSite object that represents the current site collection, as follows:
SPSite oSiteCollection = SPContext.Current.Site;

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. If you create your own SPSite object, you can use the Dispose method to close the object. You can also instead implement a using statement so that the .NET Framework common language runtime (CLR) automatically releases the memory that is used to store the site collection as follows:
using (SPSite oSiteCollection = new SPSite(“Absolute_URL”)



(The oSiteCollection will be discarded at the end of the scope)

SPSite.features returns a collection of SPFeatures objects. Such collection is Microsoft.Sharepoint.SPFatureCollection

SPFeatureCollection.ADD(GUID): Activates a feature by using the feature definition with the specified ID to create a new SPFeature object and then add it to the collection.


SPSite.OpenWeb() – Returns the Web site that is associated with the URL that is used in an SPSite constructor.
OpenWeb(Guid) – Returns the Web site with the specified GUID.
OpenWeb(String) – Returns the Web site that is located at the specified server-relative or site-relative URL.
OpenWeb(String, Boolean) – Returns the Web site that is located at the specified server-relative or site-relative URL based on a Boolean value that specifies whether the exact URL must be supplied.

When used in conjunction with an SPSite constructor, the OpenWeb method returns the lowest-level site specified by the URL
that is passed as parameter for the constructor. For more information about using the OpenWeb method with an SPSite constructor, see the OpenWeb method overload. The following code example returns the Web site that is located at http://Server_Name/sites/Site_Name/Subsite_Name

string strUrl = http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx”;

using (SPSite oSiteCollection = new SPSite(strUrl))


using(SPWeb oWebsite = oSiteCollection.OpenWeb())





Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: