创建 Sharepoint/MOSS 站点地图

发布于 2024-07-25 13:41:42 字数 1579 浏览 4 评论 0原文

我正在尝试为我的 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();

但这似乎返回网站集中的所有内容(例如列表、调查)。 我只想显示 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());
}

除了在平面列表中返回所有网络的问题之外,这是完美的。

理想情况下,我希望能够添加缩进以显示子网站。

I'm trying to create a sitemap for my MOSS publishing site, i've got two approaches but seem to be stuck with both.

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();

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小嗷兮 2024-08-01 13:41:42

一般来说,使用对象模型进行递归不是一个好主意。 这样做的速度非常慢并且需要大量资源。 PortalSiteMapProvider 已为您预先缓存,可以在几毫秒内解析整个站点结构。

关于您关于 SPSite.AllWebs 的问题,该属性确实返回所有网站的平面列表。 这就是它的用途。 如果您只需要直接子网站的列表,请使用SPSite.RootWeb.Webs属性。 递归 .Webs 属性中的每个 SPWeb,并依次调用它们的 .Webs 属性以获取树视图。

另外,在处理对象模型时,请确保处置每个网络和站点。 如果你不这样做,这将导致严重的问题。 这包括处理 .Webs 集合中的每个 Web,即使您没有接触过它。

编辑:

要使 PortalSiteMapProvider 仅返回网站,请将其 IncludePages 属性设置为 false

Generally it's a bad idea to use the object model for recursion. It's extremely slow and resource-intensive to do this. PortalSiteMapProvider is pre-cached for you and can tear through an entire site structure in milliseconds.

Regarding your question about SPSite.AllWebs, that property does return a flat list of all webs. That's what it's for. If you want a list of only the immediate child webs, use the SPSite.RootWeb.Webs property. Recurse over each SPWeb in the .Webs property, and call their .Webs property in turn to get a tree-view.

Also, when dealing with the object model, make sure to DISPOSE EVERY WEB AND SITE. This will cause epic bad problems if you don't. This includes disposing every web in the .Webs collection, even if you haven't touched it.

Edit:

To get the PortalSiteMapProvider to return only webs, set its IncludePages property to false.

残花月 2024-08-01 13:41:42

您是否尝试过使用 PortalSiteMapNode.Type 属性检查 foreach 循环中每个节点的类型并仅显示 NodeTypes.Area 类型的节点?

Have you tried checking the type of every node in the foreach loop using the PortalSiteMapNode.Type property and displaying only nodes of type NodeTypes.Area?

百思不得你姐 2024-08-01 13:41:42

感谢大家的回复,这就是我想到的,

        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);
            }
        }
    }

我发现这些文章有帮助

http://blogs.msdn.com/ecm/archive/2007/05/23/increased-performance-for-moss-apps-using- the-portalsitemapprovider.aspx

http://blogs .mosshosting.com/archive/tags/SharePoint%20Object%20Model/default.aspx

http://www.hezser.de/blog/archive/tags/SPQuery/default.aspx

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.msdn.com/ecm/archive/2007/05/23/increased-performance-for-moss-apps-using-the-portalsitemapprovider.aspx

http://blogs.mosshosting.com/archive/tags/SharePoint%20Object%20Model/default.aspx

http://www.hezser.de/blog/archive/tags/SPQuery/default.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文