Note that there are some explanatory texts on larger screens.

plurals
  1. POSiteMap Behaviour
    text
    copied!<p>I've had a good look through a load of MS documentation only to find a tree view like structure to the use of sitemaps. I don't suppose anyone's aware of how it's possible to have a folder-like structure for sitemap navigation? Take for example a structure as follows</p> <pre><code>Home About Me.aspx MyFamily.aspx MyPets.aspx Contact Telephone.aspx Email.aspx Disclaimer.aspx </code></pre> <p>The "About" and "Contact" would be folders, but the sitemap is never hierarchical on a single page. So, I would have my root page with two menu items, one would be "Home" which acts like a folder to drill down into the about and contact menus, and the other is a link to the page for the disclaimer. I want to be able to click on Home which will reload the menu with the links for "About" and "Contact" and hide "Home" and "Disclaimer" altogether.</p> <pre><code>Home &gt; Disclaimer </code></pre> <p>Then click on home and you would get</p> <pre><code>About &gt; Contact &gt; </code></pre> <p>Then when clicking on about you'd get</p> <pre><code>Me My Family My Pets </code></pre> <p>Every menu would have an "up" menu to come back out a folder.</p> <p>I can't see there being an easy solution, but at the moment we use static html pages that are in different folders all over our web application. This is something that needs changing as you can well imagine.</p> <p>Any ideas?</p> <p><strong>EDIT</strong></p> <p>I've had to come up with a VB.NET solution</p> <pre><code>&lt;script runat="server"&gt; Private Function GetSecondaryNavItems() As String Dim sRet As String = "" Dim oCurrNode As System.Web.SiteMapNode = Nothing Dim oCurrParentNode As System.Web.SiteMapNode = Nothing 'Dim sCurrPage As String = GetURL(Request.ServerVariables("SCRIPT_NAME").ToLower()) Dim sCurrPage As String = GetURL(HttpContext.Current.Request.ServerVariables("SCRIPT_NAME").ToLower()) oCurrNode = GetCurrentNode(sCurrPage, SiteMap.RootNode) If Not oCurrNode Is Nothing Then oCurrParentNode = oCurrNode.ParentNode End If If Not oCurrParentNode Is Nothing Then If Not oCurrParentNode Is SiteMap.RootNode Then sRet += "Parent Folder Link" If Not oCurrNode Is Nothing Then For Each oChild As SiteMapNode In oCurrParentNode.ChildNodes sRet += "Link for child" Next End If End If End If Return sRet End Function Private Function GetURL(ByVal fullURL As String) As String Return fullURL.Substring(fullURL.LastIndexOf("/")) End Function Private Function GetCurrentNode(ByVal _sCurrentPageURL As String, ByVal _oNode As SiteMapNode) As SiteMapNode Dim oNodeRet As SiteMapNode = Nothing For Each oNodeCheck As SiteMapNode In _oNode.ChildNodes If oNodeCheck.HasChildNodes = True Then oNodeRet = GetCurrentNode(_sCurrentPageURL, oNodeCheck) End If If oNodeRet Is Nothing Then Exit For End If Dim sURL As String = oNodeCheck.Url.ToLower() Dim iPos As Integer = sURL.IndexOf("?") If iPos &gt; 0 Then sURL = sURL.Substring(0, iPos) End If iPos = sURL.LastIndexOf("/") If iPos &gt; 0 Then sURL = sURL.Substring(iPos) End If If sURL = _sCurrentPageURL Then oNodeRet = oNodeCheck Exit For End If Next Return oNodeRet End Function &lt;/script&gt; </code></pre> <p>This is in the master page file directly (temporary, I'll place it in the code behind model later).</p> <p>I've then got this in the body</p> <pre><code>&lt;div id="sidebar"&gt; &lt;%= GetSecondaryNavItems() %&gt; &lt;/div&gt; </code></pre> <p>Again, temporarily just to test. It doesn't actually output anything but then I'm thinking my GetURL definition is incorrect. I was assuming it was just getting the actual file? I could be very wrong though :)</p> <p><strong>EDIT EDIT</strong>: For some reason I'm not getting any output, so I thought it was my sitemap. I'll need to debug it but I'm remoting in at the moment so it's quite slow ;)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" &gt; &lt;siteMapNode url="Accounts/Default.aspx" title="Accounts" description="Accounts"&gt; &lt;siteMapNode url="Accounts/Test.aspx" title="Client Balances" description="Client Balances"&gt; &lt;siteMapNode url="Hello.aspx" title="Hello" description="rarar" /&gt; &lt;siteMapNode url="Hiya.aspx" title="Hiya" description="rarar" /&gt; &lt;/siteMapNode&gt; &lt;siteMapNode url="Test.aspx" title="Test" description="rarar" /&gt; &lt;/siteMapNode&gt; &lt;/siteMap&gt; </code></pre> <p>Here's the example sitemap.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload