Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Code Rewrite

Code Rewrite

Scheduled Pinned Locked Moved C#
csharphelpasp-net
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jacob Koppang
    wrote on last edited by
    #1

    I need the two following functions rewritten to be recursive. It's from June's issue of MSDN Magazine, the article about a breadcumb/sitemap control for ASP.Net 1.1. I've translated into C#, but I'm not good with recursion (never have been), so any help would be greatly apprecited! Oh, and one other thing, the web.sitemap file that it reads from is 3 levels deep, these methods take advantage of that (), but as you could guess, the web.sitemap file could be infinately deep(that's what the recursiveness is for, as you know). private SiteMapPath GetSiteMapPath() { SiteMapPath objPath = new SiteMapPath(); SiteMapNode objCurrentNode = GetCurrentNode(); SiteMapNode objTempNode = new SiteMapNode(); int i = 0; bool found = false; // always add the root node objPath.Add(this.siteMapNode); if(objCurrentNode != this.siteMapNode) { while(!found) { objTempNode = this.siteMapNode.NodeList[i]; if(objTempNode == objCurrentNode) { objPath.Add(objTempNode); found = true; } else { if(objTempNode.HasLeaf) { foreach(SiteMapNode objNode in objTempNode.NodeList) { if(objNode == objCurrentNode) { objPath.Add(objTempNode); objPath.Add(objNode); found = true; break; } } } } i += 1; } } return objPath; } private SiteMapNode GetCurrentNode() { SiteMapNode resultNode = new SiteMapNode(); SiteMapNode tempNode = new SiteMapNode(); int i = 0; bool found = false; if(this.siteMapNode.Url.Equals(this.currentUrl.PathAndQuery)) resultNode = this.siteMapNode; else { while(!found) { tempNode = this.siteMapNode.NodeList[i]; if(tempNode.Url.Equals(this.currentUrl.PathAndQuery)) { resultNode = tempNode; found = true; } else { if(tempNode.HasLeaf) { foreach(SiteMapNode node in tempNode.NodeList) { if(node.Url.Equals(this.currentUrl.PathAndQuery)) { resultNode = node; found = true; break; } } } } i += 1; } } return resultNode; }

    H 1 Reply Last reply
    0
    • J Jacob Koppang

      I need the two following functions rewritten to be recursive. It's from June's issue of MSDN Magazine, the article about a breadcumb/sitemap control for ASP.Net 1.1. I've translated into C#, but I'm not good with recursion (never have been), so any help would be greatly apprecited! Oh, and one other thing, the web.sitemap file that it reads from is 3 levels deep, these methods take advantage of that (), but as you could guess, the web.sitemap file could be infinately deep(that's what the recursiveness is for, as you know). private SiteMapPath GetSiteMapPath() { SiteMapPath objPath = new SiteMapPath(); SiteMapNode objCurrentNode = GetCurrentNode(); SiteMapNode objTempNode = new SiteMapNode(); int i = 0; bool found = false; // always add the root node objPath.Add(this.siteMapNode); if(objCurrentNode != this.siteMapNode) { while(!found) { objTempNode = this.siteMapNode.NodeList[i]; if(objTempNode == objCurrentNode) { objPath.Add(objTempNode); found = true; } else { if(objTempNode.HasLeaf) { foreach(SiteMapNode objNode in objTempNode.NodeList) { if(objNode == objCurrentNode) { objPath.Add(objTempNode); objPath.Add(objNode); found = true; break; } } } } i += 1; } } return objPath; } private SiteMapNode GetCurrentNode() { SiteMapNode resultNode = new SiteMapNode(); SiteMapNode tempNode = new SiteMapNode(); int i = 0; bool found = false; if(this.siteMapNode.Url.Equals(this.currentUrl.PathAndQuery)) resultNode = this.siteMapNode; else { while(!found) { tempNode = this.siteMapNode.NodeList[i]; if(tempNode.Url.Equals(this.currentUrl.PathAndQuery)) { resultNode = tempNode; found = true; } else { if(tempNode.HasLeaf) { foreach(SiteMapNode node in tempNode.NodeList) { if(node.Url.Equals(this.currentUrl.PathAndQuery)) { resultNode = node; found = true; break; } } } } i += 1; } } return resultNode; }

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Recursion is not hard. It's simply a method calling itself, passing the argument necessary for the next loop (or acting on a reference object in the case of object-oriented platforms like .NET). If you're having troubles and don't understand recursion (which you might want to read up on, since it's a pretty basic requirement of larger development efforts), take a look at some of the other breadcrumb controls for ASP.NET alread on this site: http://www.codeproject.com/info/search.asp?&cats=3&cats=4&cats=5&cats=6&searchkw=breadcrumb[^] Most even use recursion, IIRC, so you can get a good idea of how it works.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups