Thursday, February 2, 2012

Programmatically get the taxonomy in ektron cms

Taxonomy is used to specify the hierarchical path in website.When ever we create a taxonomy for website we need to follow the menu structure in work area.Here i will show how to create a Bread crumb using Taxonomy.Before get the bread crumb path we have to know about condition which are get the child and parent items in taxonomy,Which API code have to use to get the data of Taxonomy.The Taxonomy API is used to get the taxonomy API.Here i have taken a bread crumb server control and assigned the path of pages.
Default.aspx:
The page is getting by using the Page Host when the page is loaded,then the content id is get by using page Id.When ever page load The taxonomy data does get all the categories. For this we need to loop through it to get the all.The parentId > 0 is t get the parent item s of current page in taxonomy
Code behind:
using System;
using Ektron.Cms;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using Ektron.Cms.Common;
using Ektron.Cms;
using System.Web.UI.WebControls;
public partial class SubPageLevel_1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Ektron.Cms.API.Content.Content contentApi = new Ektron.Cms.API.Content.Content();
ContentData content = contentApi.GetContent(PageHost1.PageID);
if (content != null)
{           
this.Master.ShowMetaTitle(content.Title);
long cid = content.Id;
if (cid > 0)
{
Ektron.Cms.API.Content.Taxonomy TaxAPI = new Ektron.Cms.API.Content.Taxonomy();
Ektron.Cms.TaxonomyBaseData[] TaxData = TaxAPI.ReadAllAssignedCategory(cid);
foreach (Ektron.Cms.TaxonomyBaseData t in TaxData)
{
if (!Page.IsPostBack)
{
long taxid = t.TaxonomyId;
Ektron.Cms.Controls.Directory taxControl = new Ektron.Cms.Controls.Directory();
taxControl.TaxonomyId = taxid;
taxControl.Page = this.Page;
taxControl.Fill();
Ektron.Cms.TaxonomyData taxData = new Ektron.Cms.TaxonomyData();
taxData = taxControl.TaxonomyTreeData;
long parentId = taxData.TaxonomyParentId;
TaxonomyData tmpTaxData = default(TaxonomyData);
Ektron.Cms.Controls.Directory tmpTaxControl = default(Ektron.Cms.Controls.Directory);
string breadCrumb = taxData.TaxonomyName;
string link = null;
while (parentId > 0)
{
tmpTaxData = new TaxonomyData();
tmpTaxControl = new Ektron.Cms.Controls.Directory();
tmpTaxControl.TaxonomyId = parentId;
tmpTaxControl.Page = this.Page;
tmpTaxControl.Fill();
tmpTaxData = tmpTaxControl.TaxonomyTreeData;
link = "" + Server.HtmlDecode(tmpTaxData.TaxonomyName) + " > ";
breadCrumb = breadCrumb.Insert(0, link);
parentId = tmpTaxData.TaxonomyParentId;
tmpTaxControl = null;
}
taxoBreadCrumb.Text = breadCrumb;
}
}
}
}
}
}
Post a Comment

Bel