5

I am confused between SPSite, SiteCollection, and SPWeb?

So my understanding is this pseudo code:

 http://My_server >>> TOP Level SIte or SPWEbApplication
 http://My_server/My_site >>>> Site Collection or SPSite

Now a site under SPSite that will be referenced through SPWeb. So what are we getting when using SPWeb.Webs?

What is a Subsite?


Test code:

SPWeb mySite = SPContext.Current.Web;
SPWebCollection sites = mySite.Webs;

foreach (SPWeb subSite in sites)
{
    Response.Write(SPEncode.HtmlEncode(subSite.Title) + "<BR>");
}
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
noob.spt
  • 971
  • 3
  • 15
  • 24
  • The official documentation from microsoft is at: [http://msdn.microsoft.com/en-us/library/ms473633(v=office.12).aspx](http://msdn.microsoft.com/en-us/library/ms473633%28v=office.12%29.aspx) – Darshan J Jun 19 '13 at 11:11

2 Answers2

15

The top level site collection SPSite is a container in which you have your root web SPWeb and subsites SPWebs under SPWebs - it takes a while to get used to the names.

Here's a nice diagram referenced from Microsoft:

enter image description here

Therefore, a subsite will be any site SPWeb under the top level web site in a site collection SPSite.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Henry C
  • 4,781
  • 4
  • 43
  • 83
2

The top level site is also referred to as the Root Web SPSite.RootWeb.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Kyle
  • 51
  • 1