Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1698
  • Last Modified:

Reading and loop in web.sitemap in C#

Hi,

I am working in ASP.net using c#

I have generated menu and navgation  using web.sitemap

How do I loop to web.sitemap programtically and get the values of each attrbutes and tag values

Please help

Many Thanks
0
tia_kamakshi
Asked:
tia_kamakshi
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
A simple recursive loop should do the trick:

 
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteMapNode rootNode = SiteMap.RootNode;
            ProcessNode(rootNode);

        }

        private void ProcessNode(SiteMapNode parentNode)
        {
            Response.Write(parentNode.Url + " (" + parentNode.Title + ")<br />");

            if (parentNode.HasChildNodes)
                foreach (SiteMapNode node in parentNode.ChildNodes)
                    ProcessNode(node);
        }

Open in new window

0
 
tia_kamakshiAuthor Commented:
Many Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now