我正在嘗試爲我的MOSS發佈站點創建站點地圖,我有兩種方法,但似乎與兩者都卡住了。創建Sharepoint/MOSS站點地圖
我的第一種方法是使用PortalSiteMapProvider,這是已經創建並很好地緩存...
PublishingWeb rootWeb = PublishingWeb.GetPublishingWeb(SPContext.Current.Site.RootWeb);
//Get the URL of the default page in the web
string defaultPageUrl = rootWeb.DefaultPage.ServerRelativeUrl;
PortalListItemSiteMapNode webNode = (PortalListItemSiteMapNode)PortalSiteMapProvider.CurrentNavSiteMapProviderNoEncode.FindSiteMapNode(defaultPageUrl);
HttpContext.Current.Response.Output.WriteLine("Top Level: " + webNode.Title.ToString() + "<br />");
//iterate through each one of the pages and subsites
foreach (SiteMapNode smnTopLevelItem in webNode.ParentNode.ChildNodes)
{
HttpContext.Current.Response.Output.WriteLine(smnTopLevelItem.Title.ToString() + "<br />");
//if the current sitemap has children, create a submenu for it
if (smnTopLevelItem.HasChildNodes)
{
foreach (SiteMapNode smnChildItem in smnTopLevelItem.ChildNodes)
{
HttpContext.Current.Response.Output.WriteLine(smnChildItem.Title.ToString() + "<br />");
}
}
}
HttpContext.Current.Response.End();
但這似乎返回網站集中一切(如列表,surverys)。我只想顯示Sharepoint網站。
我的另一種方法是使用這段代碼..
SPSite siteCollection = new SPSite("http://example.org");
SPWebCollection sites = siteCollection.AllWebs;
foreach (SPWeb site in sites)
{
Console.WriteLine(site.Title.ToString() + " " + site.ServerRelativeUrl.ToString());
}
這是完美的,除了在平面列表返回所有的網的問題。
理想情況下,我希望能夠添加縮進來顯示子網。
確定冷靜,我想使用PortalSiteMapProvider但我不知道該如何限制輸出才網。 – Rob 2009-06-24 16:43:46