Creating Sharepoint/MOSS sitemap

懵懂的女人 提交于 2019-12-06 07:26:14

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.

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?

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!