Create new toolbox section in code

Posted by Community Admin on 04-Aug-2018 19:13

Create new toolbox section in code

All Replies

Posted by Community Admin on 12-Mar-2012 00:00

Hi, 

Can anyone point me to the right direction on how to create a new Section in code (or fluent api)
Toolboxes -> PageControls -> Sections 

I would like to manage all the controls we have created in our module.

thanks,

Posted by Community Admin on 15-Mar-2012 00:00

Hello Mike,

Thank you for using our services.
Please find below a sample method demonstrating how you can register a control in your Toolbox, and if the section does not exist a new one will be created, I believe you might find it useful:

public static void RegisterControl(string controlName, Type controlType, string toolboxName, string sectionName)
       
           var configManager = ConfigManager.GetManager();
           var config = configManager.GetSection<ToolboxesConfig>();
 
           var controls = config.Toolboxes[toolboxName];
           var section = controls.Sections.Where<ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();
 
           if (section == null)
           
               section = new ToolboxSection(controls.Sections)
               
                   Name = sectionName,
                   Title = sectionName,
                   Description = sectionName,
                   ResourceClassId = typeof(PageResources).Name
               ;
               controls.Sections.Add(section);
           
 
           if (!section.Tools.Any<ToolboxItem>(e => e.Name == controlName))
           
               var tool = new ToolboxItem(section.Tools)
               
                   Name = controlName,
                   Title = controlName,
                   Description = controlName,
                   ControlType = controlType.AssemblyQualifiedName
               ;
               section.Tools.Add(tool);
           
 
           configManager.SaveSection(config);
       


All the best,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed