创建Sharepoint/MOSS网站地图 [英] Creating Sharepoint/MOSS sitemap
问题描述
我正在尝试为我的MOSS发布站点创建站点地图,我有两种方法,但似乎都被这两种方法所困扰.
I'm trying to create a sitemap for my MOSS publishing site, i've got two approaches but seem to be stuck with both.
我的第一种方法是使用PortalSiteMapProvider,该门户已经创建并且可以很好地缓存...
My first approach is to use the PortalSiteMapProvider, which is already created and nicely cached...
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网站.
but this seems to return everything in the site collection (e.g. lists, surverys). I only want to show the Sharepoint webs.
我的另一种方法是使用这段代码.
My other approach was to use this piece of code..
SPSite siteCollection = new SPSite("http://example.org");
SPWebCollection sites = siteCollection.AllWebs;
foreach (SPWeb site in sites)
{
Console.WriteLine(site.Title.ToString() + " " + site.ServerRelativeUrl.ToString());
}
除了将所有网站归还到固定列表中的问题之外,这还算是完美的.
Which is perfect, apart from the problem of returning all the webs in a flat list.
理想情况下,我希望能够添加缩进以显示子站点.
Ideally I want to be able to add indentation to show child webs.
推荐答案
感谢大家的回覆,这就是我想出的
thanks for the replys everyone, this is what I came up with
public ListSiteMap()
{
PortalSiteMapProvider portalProvider1 = PortalSiteMapProvider.WebSiteMapProvider;
portalProvider1.DynamicChildLimit = 0;
portalProvider1.EncodeOutput = true;
SPWeb web = SPContext.Current.Site.RootWeb;
PortalSiteMapNode webNode = (PortalSiteMapNode)portalProvider1.FindSiteMapNode(web.ServerRelativeUrl);
if (webNode == null || webNode.Type != NodeTypes.Area) return;
Console.WriteLine(webNode.Title.ToString() + " - " + webNode.Description.ToString());
// get the child nodes (sub sites)
ProcessSubWeb(webNode);
}
private void ProcessSubWeb(PortalSiteMapNode webNode)
{
foreach (PortalSiteMapNode childNode in webNode.ChildNodes)
{
Console.WriteLine(childNode.Title.ToString() + " - " + childNode.Description.ToString());
//if the current web has children, call method again
if (childNode.HasChildNodes)
{
ProcessSubWeb(childNode);
}
}
}
我发现这些文章有所帮助
I found these articles helped
http://blogs.mosshosting.com/archive /tags/SharePoint%20Object%20Model/default.aspx
http://www.hezser.de/blog/archive /tags/SPQuery/default.aspx
这篇关于创建Sharepoint/MOSS网站地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!