In this article we will discuss about SPContext class in SharePoint 2010. Also you can check out my previous posts on:
- Represents the context of an HTTP request in Microsoft SharePoint Foundation.
- This class also available in SharePoint Sandboxed solution also.
- Present in the Assembly Microsoft.SharePoint.dll.
- This class returns current information about list, site and also site collection, also you can retrieve current user name also.
- Here are some example of SPContext class
string userLoginName=SPContext.Current.Web.CurrentUser.LoginName; //This will return current login name.
SPList currentList = SPContext.Current.List; //Give you the current list associated with the context
SPWeb currentWeb = SPContext.Current.Web; //Returns the current site associated with the context
SPSite currentSite = SPContext.Current.Site; //Returns current site collection associated with the context
SPWebApplication currentWebApplication = SPContext.Current.Site.WebApplication; //Returns current web application associated with the context.
SPContext.Current.SiteFeatures //Give you the activated site collection features of the SharePoint context.