Following is the code to implement the breadcrumbs in asp.net

/* Add Web.sitemap.  To add this file, right click on Project Folder, select option "Add New Item".
Select Site Map and add file.  Your file should contain nodes like below :

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0&quot; >
<siteMapNode url="~/default.aspx" title="Home"  description="Home">
<siteMapNode url="~/OrderDetails/OrderList.aspx" title="OrderList" description="" />
<siteMapNode url="" title="Search" description="" >
<siteMapNode url="~/GallerySearch/NewGallarySearch.aspx" title="Gallary Search"  description=""/>
<siteMapNode url="~/Search/Search.aspx" title="Advance Search"  description=""/>
</siteMapNode>
<siteMapNode url="" title="Administration"  description="">
<siteMapNode url="~/Partner/PartnerList.aspx" title="Partner List"  description="" >
<siteMapNode url="~/Partner/PartnerSummary.aspx" title="Partner Summary"  description="">
<siteMapNode url="~/Partner/EditPartner.aspx" title="Partner Edit"  description="" />
<siteMapNode url="~/Partner/PartnerProduct.aspx" title="Partner Product" description="" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
<siteMapNode url="~/User/ViewaccountInfo.aspx" title="My Profile" description="" />
<siteMapNode url="" title="Help"  description="" />
</siteMapNode>
</siteMap>

/* To implement Breadcrumb upto first level of Querystring, add following code in your Global.aspx */

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>

<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(AppendQueryString);
}

void Application_End(object sender, EventArgs e)
{
//  Code that runs on application shutdown
}

void Application_Error(object sender, EventArgs e)
{
//Exception objErr = Server.GetLastError().GetBaseException();
//string err = "Error in: " + Request.Url.ToString() +
//                  ". Error Message:" + objErr.Message.ToString();
//if (Session["SessionInformation"] == null)
//{
//    Server.Transfer("../Logout.aspx");
//}
}

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
//HttpContext context = HttpContext.Current;
//HttpCookieCollection cookies = context.Request.Cookies;
}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application_Error(sender, e);
}

//Function to add breadcrumb with Querystring.
SiteMapNode AppendQueryString(object o, SiteMapResolveEventArgs e)
{
if (SiteMap.CurrentNode != null)
{
SiteMapNode temp;
temp = SiteMap.CurrentNode.Clone(true);
Uri u = new Uri(e.Context.Request.Url.ToString());
temp.Url += u.Query;
if (temp.ParentNode != null)
{
temp.ParentNode.Url += u.Query;
}
return temp;
}
else
{
return null;
}
}

</script>

/* Add following tag in Master Page, where you want to implement site map.

<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" ParentLevelsDisplayed="8"
Font-Size="0.8em" PathSeparator=" ->">
<PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#284E98" />
<RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />
</asp:SiteMapPath>

Gauri Deshpande / Pawan Kumar

Pawankkmr@hotmail.com

Advertisements