Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 258035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:08:49+00:00 2026-05-11T22:08:49+00:00

I’m trying to create a sitemap for my MOSS publishing site, i’ve got two

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:08:49+00:00Added an answer on May 11, 2026 at 10:08 pm

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.