Section Icons

Section Icons

The Sitecore.Configuration.Factory class encapsulates the general information available in the web.config file and contains methods that provide access to this information and the means to override it.
  1. Create an object for the database where the item is located - replace SitecoreDB with the name of the Sitecore database where you want to perform the update, typically “master”
  2. Create an object for the target template in the database - replace templatepath with the relative path to the template in the Templates portion of the Content Tree, such as “user defined/template1”
  3. Create an object for the section of the template where the icon will be assigned - replace sectionname with the name of the section, such as “Data” for common content
  4. Verify the section exists
  5. Open the edit state for the item
  6. Create an object for the target icon in the database - replace iconpath with the relative path to the icon in the Content Tree, such as “business/16x16/icon.png”
  7. Close the edit state for the item


C# Web Control Code

Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("SitecoreDB");

Sitecore.Data.Items.TemplateItem template = db.Templates["templatepath"]; Sitecore.Data.Items.TemplateSectionItem section = sample.GetSection("sectionname");

 

if (section!=null || section.InnerItem.Parent.ID==template.ID)

{

      section.InnerItem. ItemEditing.BeginEdit();

section.InnerItem.Appearance.Icon = "iconpath";

section.InnerItem. ItemEditing.EndEdit();



}