Read and modify a configuration
To read and modify configuration, you use Config and ConfigManager.
The ConfigManager class reads configurations from folder ~/App_Data/Sitefinity/Configuration. The configuration section is stored in a file with the same name as the configuration class. The extension is .config. The file is created only if the configuration differs from the default values.
NOTE: To create the file, you can copy and modify an existing configuration file.
- The
PageAppearanceConfig.configcontains the following code:XML<?xml version="1.0" encoding="utf-8" ?> <pageAppearanceConfig xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="4.2.1641.0" remoteOnly="False" country="USA"> <color background="008000" foreground="D3D3D3"/> <Fonts> <add size="18" name="Verdana" /> </Fonts> </pageAppearanceConfig> - To read values from
PageAppearanceConfig.config, use the following code:C#using Telerik.Sitefinity.Configuration; namespace SitefinityWebApp { public class ReadValuesPageAppearanceConfig { public static void ReadPageAppearanceConfig() { PageAppearanceConfig config = Config.Get<PageAppearanceConfig>(); var pageColor = config.Color; var pageFontSize = config.Fonts["Verdana"].Size; } } } - To modify values from
PageAppearanceConfig.config, use the following code:C#using Telerik.Sitefinity.Configuration; namespace SitefinityWebApp { public class ModifyValuesPageAppearanceConfig { public static void ReadPageAppearanceConfig() { ConfigManager manager = ConfigManager.GetManager(); PageAppearanceConfig config = manager.GetSection<PageAppearanceConfig>(); config.Fonts.Add(new FontElement(config.Fonts) { Name = "TimesNewRoman", Size = 16, }); manager.SaveSection(config); } } } - To modify nested configurations, for example,
LoadBalancingConfig, which is part ofSystemConfig.config, use the following code:C#using Telerik.Sitefinity.Configuration; using Telerik.Sitefinity.LoadBalancing; using Telerik.Sitefinity.LoadBalancing.Configuration; using Telerik.Sitefinity.Services; namespace SitefinityWebApp { public class ModifyNestedConfigs { public void NestedConfigs() { ConfigManager manager = ConfigManager.GetManager(); SystemConfig systemConfig = manager.GetSection<SystemConfig>(); var loadBalancingConfig = systemConfig.LoadBalancingConfig; loadBalancingConfig.Senders.Add(new TypeNameConfigElement(loadBalancingConfig) { Value = typeof(WebServiceSystemMessageSender).FullName }); manager.SaveSection(systemConfig); } } }
NOTE: The
PageAppearanceConfigclass in the samples above is a custom class. For more information about creating custom configuration classes, see Create a new configuration.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.