Tips and Tricks From MOSS 2007 Development Training
class Program
{
static void Main()
{
string sitePath = "http://litwareinc.com";
// enter object model through site collection.
SPSite siteCollection = new SPSite(sitePath);
// obtain reference to top-level site.
SPWeb site = siteCollection.RootWeb;
SPWeb site1 = site; //this actually create a copy of site, I will have followup blog on this after I find out how the assignment of an reference type got a copy instead of a pointer
site1.Dispose(); //this does not affect site
// enumerate through lists of site
foreach (SPList list in site.Lists)
{
Console.WriteLine(list.Title);
}
// clean up by calling Dispose.
site.Dispose();
siteCollection.RootWeb.Dispose();
siteCollection.Dispose();
}
}