Custom Crumbline based on URL

by David Kiff 8. July 2007 13:41

A few people have asked me how to create a crumbline based on the URL, for example:

www.mydomain.com/Hello_World/MyPage.aspx
www.mydomain.com/DotNet/Examples/FirstExample.aspx

The first one should display:
Home > Hello_World > MyPage.aspx
Second should display:
Home > DotNet > Examples > FirstExample.aspx

Here is a method for doing so:

private string CreateCrumb()
{
    string[] pathNames = Request.RawUrl.Split(‘/’);
    System.Text.StringBuilder crumbLine = new System.Text.StringBuilder();
    for (int i = 1; i < pathNames.Length; i++)
    {
        crumbLine.Append(pathNames.GetValue(i));
        if (i != pathNames.Length - 1)
        {
            crumbLine.Append(" > ");
        }
    }
    return crumbLine.ToString();
}

Tags:

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading