共用方式為


SPContext.Current Property

Gets the context of the current HTTP request in Microsoft SharePoint Foundation.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableAttribute> _
Public Shared ReadOnly Property Current As SPContext
    Get
'Usage
Dim value As SPContext

value = SPContext.Current
[ClientCallableAttribute]
public static SPContext Current { get; }

Property Value

Type: Microsoft.SharePoint.SPContext
The SharePoint Foundation context.

Remarks

The Current property provides properties that access various objects within the current SharePoint Foundation context, for example, the current list, Web site, site collection, or Web application.

Examples

The following example uses the Current property to access the collection of site collections in the current Web applicaton.

Dim myApp As SPWebApplication = SPContext.Current.Site.WebApplication
Dim sites As SPSiteCollection = myApp.Sites
         
Dim site As SPSite

For Each site In  sites
   Response.Write((site.Url + "<BR>"))
Next site
SPWebApplication oWebApplicationCurrent = SPContext.Current.Site.WebApplication;
SPSiteCollection collSites = oWebApplicationCurrent.Sites;

foreach (SPSite oSite in collSites)
{
   Response.Write(oSite.Url + "<BR>");
   oSite.Dispose();
}

See Also

Reference

SPContext Class

SPContext Members

Microsoft.SharePoint Namespace