Created
April 4, 2013 12:28
-
-
Save moaschterle/5309966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Intranet | |
{ | |
public class CustomBreadcrumpCMS | |
{ | |
SmgIntranetContainer mycontainer; | |
public CustomBreadcrumpCMS(string lang) | |
{ | |
mycontainer = GlobalContainer.Instance; | |
GenerateMyBreadCrump(lang); | |
} | |
private Table myBreadCrump; | |
public Table MyBreadCrump | |
{ | |
get { return myBreadCrump; } | |
set { myBreadCrump = value; } | |
} | |
protected void GenerateMyBreadCrump(string lang) | |
{ | |
try | |
{ | |
// The current HttpContext. | |
HttpContext currentContext = HttpContext.Current; | |
if (currentContext != null) | |
{ | |
string rawUrl = HttpContext.Current.Request.RawUrl; | |
string myurl = "~" + rawUrl; | |
var mybreadcrump = (from xy in mycontainer.MenuCmsSet where xy.URL == myurl select xy).FirstOrDefault(); | |
LiteralControl separator = new LiteralControl(); | |
separator.Text = " > "; | |
myCurrentTree = new Dictionary<string,string>(); | |
MyBreadCrump = new Table(); | |
TableRow myrow = new TableRow(); | |
TableCell mycell = new TableCell(); | |
//var root = GetRoot(mybreadcrump); | |
//MyCurrentTree.Add(mybreadcrump.URL, mybreadcrump.NameDE); | |
SetMyCurrentTree(mybreadcrump); | |
int i = 0; | |
foreach(KeyValuePair<string,string> kp in MyCurrentTree) | |
{ | |
if(i > 0) | |
mycell.Controls.Add(separator); | |
LiteralControl myliteral = new LiteralControl(); | |
if(kp.Key == myurl) | |
myliteral.Text = "<b><a href='" + kp.Key + "'>" + kp.Value + "</a></b>"; | |
else | |
myliteral.Text = "<a href='" + kp.Key + "'>" + kp.Value + "</a>"; | |
mycell.Controls.Add(myliteral); | |
i++; | |
} | |
myrow.Controls.Add(mycell); | |
MyBreadCrump.Controls.Add(myrow); | |
} | |
else | |
{ | |
throw new Exception("HttpContext.Current is Invalid"); | |
} | |
} | |
catch (Exception e) | |
{ | |
throw new NotSupportedException("HttpContext.Current is Invalid", e); | |
} | |
} | |
private void SetMyCurrentTree(MenuCms currentitem) | |
{ | |
if (currentitem.Parent != null) | |
SetMyCurrentTree(currentitem.Parent); | |
myCurrentTree.Add(currentitem.URL, currentitem.NameDE); | |
} | |
private Dictionary<string,string> myCurrentTree; | |
public Dictionary<string,string> MyCurrentTree | |
{ | |
get { return myCurrentTree; } | |
set { myCurrentTree = value; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment