Custom app.config section with a simple list of “add” elements

Full example with code based on OP config file: <configuration> <configSections> <section name=”registerCompanies” type=”My.MyConfigSection, My.Assembly” /> </configSections> <registerCompanies> <add name=”Tata Motors” code=”Tata”/> <add name=”Honda Motors” code=”Honda”/> </registerCompanies> </configuration> Here is the sample code to implement a custom config section with collapsed collection using System.Configuration; namespace My { public class MyConfigSection : ConfigurationSection { [ConfigurationProperty(“”, IsRequired … Read more

How to create custom config section in app.config? [duplicate]

Import namespace : using System.Configuration; Create ConfigurationElement Company : public class Company : ConfigurationElement { [ConfigurationProperty(“name”, IsRequired = true)] public string Name { get { return this[“name”] as string; } } [ConfigurationProperty(“code”, IsRequired = true)] public string Code { get { return this[“code”] as string; } } } ConfigurationElementCollection: public class Companies : ConfigurationElementCollection { … Read more

Variables within app.config/web.config

A slightly more complicated, but far more flexible, alternative is to create a class that represents a configuration section. In your app.config / web.config file, you can have this: <?xml version=”1.0″ encoding=”utf-8″ ?> <configuration> <!– This section must be the first section within the <configuration> node –> <configSections> <section name=”DirectoryInfo” type=”MyProjectNamespace.DirectoryInfoConfigSection, MyProjectAssemblyName” /> </configSections> <DirectoryInfo> … Read more

Settings.settings vs. app.config in .NET desktop app [duplicate]

Why two mechanisms and not just one? They serve different purposes. The settings API offers read/write access from the application, whereas config is read only (unless you write the file in code). Settings can be defined per user or per application, and are designed to be volatile. User settings are written to hidden folder within … Read more

Developer specific app.config/web.config files in Visual Studio

We use a system that combines several of the existing answers on this page, plus draws on this suggestion by Scott Hanselman. In short, what we did was to have a common app.config / web.config, and to have most of the specific settings in individual files, as suggested by other answers here. e.g. for our … Read more

App.config: User vs Application Scope

Basically, application settings cannot be changed during the running of a program and user settings can. These user settings should then be saved so the user is presented with a familiar experience when (s)he runs the application next. Edit: For examples, you might write your application with different modules, and need to ensure that your … Read more

Only one configSections element allowed per config file and if present must be the first child of the root configuration element

The error message itself actually details the correct fix: configSections must be the first child* of the root element: *emphasis added So just move the configSections to the top: <configuration> <configSections> <section name=”Reva.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” /> <section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” /> </configSections> <startup useLegacyV2RuntimeActivationPolicy=”true”> <supportedRuntime version=”v4.0″/> </startup> </configuration>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)