Export (0) Print
Expand All

SPSite Constructor (String)

Windows SharePoint Services 3

Initializes a new instance of the SPSite class based on the specified absolute URL.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPSite(
	string requestUrl
)

Parameters

requestUrl
Type: System.String
A string that specifies the absolute URL for the site collection.

The URL that is passed to the SPSite constructor does not need to match a site collection URL exactly.

The following code example returns the site collection that is located at http://Server_Name/sites/Site_Name even though the URL that is passed to the constructor does not match the site collection URL.

using (SPSite oSiteCollection = new SPSite("http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx"))
{
    ...
}

The next code example creates an SPSite object using System.Environment.MachineName.

using (SPSite oSiteCollection = new SPSite("http://" + System.Environment.MachineName + "/sites/Site_Name"))
{
    ...
}
NoteNote

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Community Additions

ADD
Show:
© 2014 Microsoft