Represents a SharePoint Foundation website.
Definition:
An SPWeb object represents a single website in SharePoint residing in a Site Collection (SPSite).
More reading:
Code example:
//through current context
SPWeb myWeb = SPContext.Current.Web;
//opening from an SPSite
SPWeb mySite = mySiteCollection.OpenWeb("http://yoursiteurl/"))
SPWeb
implements the IDisposable
interface so you should close the object when you no longer need it. This is not the case when you're object is assigned through a Context. So in the first line, the Dispose()
should not be called. You can close it manually or use the using statement to do this for you:
//manually
myWeb.Dispose();
//using statement
using(SPSite mySiteCollection = new SPSite("http://mysharepointsite/"))
{
using(SPWeb myWeb = mySiteCollection.OpenWeb("http://yoursiteurl/"))
{
//get the title of the website
string name = myWeb.Title;
}
}