WSS的完整的对象模型可以参考MSDN:

http://msdn.microsoft.com/en-us/library/ms473633.aspx

但是对某些接触不是太深入,或者经常只使用SPSite和SPWeb的开发人员,经常会弄不清楚SiteCollection、Site、WebCollection、Web之间的区别,下面用图示说明:

image

 

需要特别注意的是:

1. SPSite在中文版里被称作“网站集”,而SPSiteCollection的直接中文意思却是“网站集”,实际上却不是真正的网站集,SPSiteCollection的意思应该是“网站集的集合”,参考上图

2. 另外Site和Web在中文里的翻译为“站点”和“网站”,和上述的概念也很容易混在一起。

2. 一个SPSite有且只能有一个顶级站点,其他站点都是它的子站点

 

使用如下代码,可以很容易的区分出上述概念的区别:

(加到自己的方法里面)

 

                //SPFarm farm = SPWebService.ContentService.Farm;
                //SPServerCollection serverCollection = farm.Servers;
                SPWebApplicationCollection webAppCollection = SPWebService.ContentService.WebApplications;

                if (webAppCollection != null)
                {
                    foreach (SPWebApplication webApplication in webAppCollection)
                    {
                        Console.WriteLine("WebApplication: " + webApplication.Name);
                        Console.WriteLine("  AppPool: " + webApplication.ApplicationPool.Name + " (" + webApplication.ApplicationPool.Status + ")");

                        foreach (SPSite site in webApplication.Sites)
                        {
                            Console.WriteLine("    SPSite Server Relative Url: " + site.ServerRelativeUrl);
                            Console.WriteLine("      Root Web Title: " + site.RootWeb.Title);
                            Console.WriteLine("      Root Web Url: " + site.RootWeb.Url);
                            foreach (SPWeb web in site.RootWeb.Webs)
                            {
                                Console.WriteLine("       Sub Web(Site) Title: " + web.Title);
                                Console.WriteLine("       Sub Web(Site) Url: " + web.Url);
                                //foreach (SPList list in web.Lists)
                                //{
                                //    Console.WriteLine("       List Title: " + list.Title);
                                //    Console.WriteLine("         Root Folder Name: " + list.RootFolder.Name);
                                //    Console.WriteLine("         Root Folder Url: " + list.RootFolder.Url);

                                //}
                            }
                        }
                    }
                }

posted on 2010-06-01 17:21  重金属  阅读(350)  评论(0编辑  收藏  举报