<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jesal gadhia &#187; sitemap</title>
	<atom:link href="http://jesal.us/tag/sitemap/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Fri, 19 Mar 2010 05:32:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Semi-Dynamic Sitemap Solution</title>
		<link>http://jesal.us/2008/01/a-semi-dynamic-sitemap-solution/</link>
		<comments>http://jesal.us/2008/01/a-semi-dynamic-sitemap-solution/#comments</comments>
		<pubDate>Sun, 13 Jan 2008 02:13:48 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[sitemap]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/01/12/a-semi-dynamic-sitemap-solution/</guid>
		<description><![CDATA[I was creating a website which had pages with multiple views. I wanted a fairly simple sitemap solution, without creating any custom sitemap provider, which could show the current view name in the breadcrumb trail like this &#8211; 
Home >> Parent Page >> Current Page >> Current View 1
Home >> Parent Page >> Current Page [...]]]></description>
			<content:encoded><![CDATA[<p>I was creating a website which had pages with multiple views. I wanted a fairly simple sitemap solution, without creating any custom sitemap provider, which could show the current view name in the breadcrumb trail like this &#8211; </p>
<p>Home >> Parent Page >> Current Page >> Current View 1<br />
Home >> Parent Page >> Current Page >> Current View 2</p>
<p>So here&#8217;s what I did to achieve that &#8211; </p>
<p><strong>MasterPage.Master:</strong></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="asp">&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %&gt;</span>
<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span class="kwrd">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">="http://www.w3.org/1999/xhtml"</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>CMS ::<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">asp:SiteMapPath</span> <span class="attr">ID</span><span class="kwrd">="SiteMapPath1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">OnPreRender</span><span class="kwrd">="SiteMapPath1_PreRender"</span> <span class="attr">PathSeparator</span><span class="kwrd">=" :  "</span> <span class="attr">RenderCurrentNodeAsLink</span><span class="kwrd">="True"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">asp:SiteMapPath</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">asp:ContentPlaceHolder</span> <span class="attr">ID</span><span class="kwrd">="ContentPlaceHolder1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">asp:ContentPlaceHolder</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span>
</pre>
<p><strong>MasterPage.master.cs:</strong></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Data;
<span class="kwrd">using</span> System.Configuration;
<span class="kwrd">using</span> System.Collections;
<span class="kwrd">using</span> System.Web;
<span class="kwrd">using</span> System.Web.Security;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> System.Web.UI.WebControls;
<span class="kwrd">using</span> System.Web.UI.WebControls.WebParts;
<span class="kwrd">using</span> System.Web.UI.HtmlControls;
<span class="kwrd">using</span> System.Collections.Generic;

<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> MasterPage : System.Web.UI.MasterPage
{
    <span class="kwrd">private</span> <span class="kwrd">string</span> _currentViewName = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">public</span> <span class="kwrd">string</span> CurrentViewName
    {
        get { <span class="kwrd">return</span> _currentViewName; }
        set { _currentViewName = <span class="kwrd">value</span>; }
    }
    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
    {
        SiteMap.SiteMapResolve += <span class="kwrd">new</span> SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
    }
    <span class="kwrd">protected</span> <span class="kwrd">void</span> SiteMapPath1_PreRender(<span class="kwrd">object</span> sender, EventArgs e)
    {
        <span class="rem">//If there is a current view name defined then add a child node to the breadcrumb trail.</span>
        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(CurrentViewName))
        {
            SiteMapNodeItem sepItem = <span class="kwrd">new</span> SiteMapNodeItem(-1, SiteMapNodeItemType.PathSeparator);
            ITemplate sepTemplate = SiteMapPath1.PathSeparatorTemplate;
            <span class="kwrd">if</span> (sepTemplate == <span class="kwrd">null</span>)
            {
                Literal separator = <span class="kwrd">new</span> Literal();
                separator.Text = SiteMapPath1.PathSeparator;
                sepItem.Controls.Add(separator);
            }
            <span class="kwrd">else</span>
            {
                sepTemplate.InstantiateIn(sepItem);
            }
            sepItem.ApplyStyle(SiteMapPath1.PathSeparatorStyle);

            SiteMapNodeItem viewItem = <span class="kwrd">new</span> SiteMapNodeItem(-1, SiteMapNodeItemType.Current);
            Literal viewName = <span class="kwrd">new</span> Literal();
            viewName.Text = CurrentViewName;
            viewItem.Controls.Add(viewName);
            viewItem.ApplyStyle(SiteMapPath1.CurrentNodeStyle);

            SiteMapPath1.Controls.AddAt(-1, sepItem);
            SiteMapPath1.Controls.AddAt(-1, viewItem);
        }
        <span class="kwrd">else</span> <span class="rem">//...if not then don't show the current node as a link.</span>
        {
            SiteMapPath mySMP = (SiteMapPath)sender;
            mySMP.RenderCurrentNodeAsLink = <span class="kwrd">false</span>;
            mySMP.DataBind();
        }
    }
    <span class="kwrd">private</span> SiteMapNode SiteMap_SiteMapResolve(Object sender, SiteMapResolveEventArgs e)
    {
        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(<span class="kwrd">true</span>);         

        <span class="rem">//If there is a current view defined then set the URLs in the breadcrumb trail </span>
        <span class="rem">//so that they point to the correct view. For example:</span>
        <span class="rem">//Home (Home.aspx) &gt; News (News.aspx?View=0) &gt; Edit (News.aspx?View=1)</span>
        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(CurrentViewName))
        {
            <span class="kwrd">string</span> currentRequest = e.Context.Request.UrlReferrer.PathAndQuery;

            <span class="kwrd">if</span> (currentNode != <span class="kwrd">null</span>)
                currentNode.Url = currentRequest;
        }

        <span class="kwrd">return</span> currentNode;
    }
}
</pre>
<p>Now you are all set. To put this code in action, just declare a curent view name like this in your pages wherever needed:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
((MasterPage)<span class="kwrd">this</span>.Master).CurrentViewName = <span class="str">"News Listing"</span>;</pre>
<p>This solution was inspired by <a href="http://weblogs.asp.net/dannychen/archive/2005/10/19/427924.aspx">this</a> blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/01/a-semi-dynamic-sitemap-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
