In this code, I'm looping through each Web in the site collection and display the Title, Site Definition Template ID, and Site Definition template Name of each Web.
using (SPSite mySite = new SPSite("http://mysite"))
{
foreach (SPWeb myWeb in mySite.AllWebs)
{
Console.WriteLine("Name: " + myWeb.Title);
Console.WriteLine("Template ID: " + myWeb.WebTemplateId.ToString());
Console.WriteLine("Template Name: " + myWeb.WebTemplate);
Console.WriteLine("====================");
myWeb.Dispose();
}
}
Note that, it is a best practice to dispose SPWeb object explicitly when we are using SPWeb in foreach statement.
0 comments:
Post a Comment