Skip to content

Instantly share code, notes, and snippets.

@toburger
Forked from moaschterle/gist:5309966
Last active December 15, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toburger/5310035 to your computer and use it in GitHub Desktop.
Save toburger/5310035 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Intranet
{
public static class CustomBreadcrumpCMS
{
public static string GenerateMyBreadCrump(IDictionary<string, string> path)
{
HttpContext currentContext = HttpContext.Current;
if (currentContext == null)
throw new InvalidOperationException("HttpContext.Current is Invalid");
string rawUrl = HttpContext.Current.Request.RawUrl;
string myurl = "~" + rawUrl;
return string
.Join(
" > ",
path.Select(kb =>
{
if(kp.Key == myurl)
return "<b><a href='" + kp.Key + "'>" + kp.Value + "</a></b>";
else
return "<a href='" + kp.Key + "'>" + kp.Value + "</a>";
}));
}
public static Dictionary<string, string> GetMyCurrentTree(MenuCms currentitem)
{
return GetParents(currentitem).Reverse().ToDictionary(i => i.Item1, i => i.Item2);
}
private static IEnumerable<Tuple<string, string>> GetParents(MenuCms currentitem)
{
yield return Tuple.Create(currentitem.URL, currentitem.NameDE);
if (currentitem.Parent != null)
foreach (var parent in GetParents(currentitem.Parent))
yield return parent;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment