SPCOntext, SPFarm, SPWebApplication, SPSite and SPWeb

SPContext —

SPContext.Web – Returns the SPWeb object that represents the site associated with the context
SPContext.Site — Returns the SPSite object that represents the site collection associated with the context
SPContext.Current — A static property that returns the SPContext object
for the current HTTP request
SPContext.List — Returns the SPList object associated with the context
SPContext.File — Returns the SPFile object that is associated with the SPListItem object returned by the Item property
SPContext.Fields — Returns the SPFieldCollection that contains the SPField objects associated with the SPListItem or SPContentType of the context
SPContext.ListItem — Returns the SPListItem object associated with the context object
SPContext.ListID — Returns the GUID of the list
associated with the context object
SPContext.ItemID — Returns the integer ID of the item
that is associated with the context object

Using SPContext:

SPContext context = SPContext.Current;
SPSite site = context.Site; // now we have a SPSite object
SPWeb web-context.Web; // now we have a SPWeb object

According to Sharepoint best practices, SPContext,Current.Site, SPContext.Web, SPContext.Current.Web
should not be explicitly disposed by user code.

SPWebApplication –

SPWebApplication is IIS Web Application.

To use SPWebApplication you must add Microsoft.Sharepoint.Administration.

SPSite –  

SPSite is Site Collection.


Using Dispose()
method is the same as using Close()
method.

SPWeb –

A site in the site collection.  

Advertisements
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: