Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Server Technologies
SDK Documentation
SPContext Class
 Current Property
SPContext.Current Property (Microsoft.SharePoint)
Gets the context of the current HTTP request in Windows SharePoint Services.

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

Visual Basic (Declaration)
Public Shared ReadOnly Property Current As SPContext
Visual Basic (Usage)
Dim value As SPContext

value = SPContext.Current
C#
public static SPContext Current { get; }

Property Value

A SPContext object that represents the Windows SharePoint Services context.

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

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

Visual Basic
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
C#
SPWebApplication oWebApplicationCurrent = SPContext.Current.Site.WebApplication;
SPSiteCollection collSites = oWebApplicationCurrent.Sites;

foreach (SPSite oSite in collSites)
{
   Response.Write(oSite.Url + "<BR>");
   oSite.Dispose();
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker