1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Register a Custom Config

Register a Custom Config

3 posts, 1 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    12 Mar 2012
    Link to this post
    The docs say to register a custom config like this
    Config.RegisterSection<PageAppearanceConfig>();

    ...should we be checking to see if it's already registered or something first though, or is that handled internally in the RegisterSection?
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    15 Mar 2012
    Link to this post
    Hi Steve,

    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);
           }
    That's the approach we've implemented in all Sitefinity SDK samples that are being created through code, so I'd recommend you to refer to this implementation , in other words check if there is already such a section, and if none, create a new one.

    Regards,
    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
    Answered
  3. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    15 Mar 2012
    Link to this post
    Perfect!
3 posts, 1 answered