How to Access Site Terms in a Commerce Server Site
You access site terms in your Commerce Server Core Systems site code by using the ProfileContext object. This topic shows how to override the default Render method for a Web form and write all site terms to the form by using HTML.
To access site terms and write them to a Web page
Create a procedure to override the default Render method.
Inside the Render method, create an instance of the Commerce Server Core Systems ProfileContext runtime object.
Write a begin tag.
For each site term in the site terms collection, write the name of the site term. Each site term must be enclosed in a begin and end tag pair.
For each site term, write the name of the site term elements. Each site term element must be enclosed in a begin and end tag pair.
Write an end tag.
Example
protected override void Render(HtmlTextWriter writer)
{
ProfileContext ctxt = CommerceContext.Current.ProfileSystem;
writer.RenderBeginTag(HtmlTextWriterTag.Ul);
foreach (string siteTermName in ctxt.SiteTermNames)
{
SiteTerm siteTerm = ctxt.GetSiteTerm(siteTermName);
writer.RenderBeginTag(HtmlTextWriterTag.Li);
writer.Write(siteTerm.Name);
writer.RenderBeginTag(HtmlTextWriterTag.Ul);
foreach (SiteTermElement element in siteTerm.Elements)
{
writer.RenderBeginTag(HtmlTextWriterTag.Li);
writer.Write(element.Name + " = " + element.Value);
writer.RenderEndTag();
}
writer.RenderEndTag();
}
writer.RenderEndTag();
}
Compiling the Code
To compile the code, you must include these namespace directives:
using System.Web.UI;
using System.Web.UI.WebControls;