title: Creating Sharepoint/MOSS sitemap
body: <p>I'm trying to create a sitemap for my MOSS publishing site, i've got two approaches but seem to be stuck with both.</p>
  
  <p>My first approach is to use the PortalSiteMapProvider, which is already created and nicely cached...</p>
  
  <pre><code>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() + "&lt;br /&gt;");
  
  //iterate through each one of the pages and subsites
  foreach (SiteMapNode smnTopLevelItem in webNode.ParentNode.ChildNodes)
  {
  
      HttpContext.Current.Response.Output.WriteLine(smnTopLevelItem.Title.ToString() + "&lt;br /&gt;");
  
      //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() + "&lt;br /&gt;");
          }
      }
  }
  
  HttpContext.Current.Response.End();
  </code></pre>
  
  <p>but this seems to return everything in the site collection (e.g. lists, surverys). I only want to show the Sharepoint webs. </p>
  
  <p>My other approach was to use this piece of code..</p>
  
  <pre><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());
  }
  </code></pre>
  
  <p>Which is perfect, apart from the problem of returning all the webs in a flat list. </p>
  
  <p>Ideally I want to be able to add indentation to show child webs.</p>