Friday, January 25, 2013

SPWeb Class with SharePoint 2013

SPWeb Class represents a web site.

The AllWebs Property of the SPSite Class will return all web sites within the site collection.

SPSite sSiteCollection = new SPSite("http://shalvin");
foreach(SPWeb sw in sSiteCollection.AllWebs)
 {
  listBox1.Items.Add(sw.Url);
  listBox1.Items.Add("Root web ? " + sw.IsRootWeb);
  listBox1.Items.Add(sw.Site);
  listBox1.Items.Add("  ");
}





The Webs property of SPWeb Calss will Return all the immediate child web sites beneath a web site.

SPcontext ctx = SPContext.Current;
SPSite site = ctx.Site;

SPWeb sw = sw.RootWeb; 
listBox1.Items.Add(web.Title);

foreach(SPWeb child in sw.Webs)
{
 listBox1.Items.Add(child.Title);
}

No comments:

Post a Comment