how to change the values in custom section in app.config file. pleease find detailed images below.
Loading
how to change the values in custom section in app.config file. pleease find detailed images below.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Jan 9, 2024, 1:00 AM EST
Suppose you have a custom section as
Then you can change the value as
using System.Configuration; namespace YourNamespace { public class CustomSettingsSection : ConfigurationSection { [ConfigurationProperty("Setting1", DefaultValue = "Value1", IsRequired = false)] public string Setting1 { get { return (string)this["Setting1"]; } set { this["Setting1"] = value; } } [ConfigurationProperty("Setting2", DefaultValue = "Value2", IsRequired = false)] public string Setting2 { get { return (string)this["Setting2"]; } set { this["Setting2"] = value; } } } } using System; using System.Configuration; class Program { static void Main() { // Load the configuration file Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Access the custom section CustomSettingsSection customSettings = (CustomSettingsSection)configuration.GetSection("customSettings"); // Modify the values customSettings.Setting1 = "NewValue1"; customSettings.Setting2 = "NewValue2"; // Save the changes configuration.Save(ConfigurationSaveMode.Modified); Console.WriteLine("Custom settings updated successfully."); } }Jithu ThomasRank #437 · 5.7K reputationPosted Jan 9, 2024, 12:50 AM EST
Hello Naveen
Good morning...
Kindly note that the mentioned image is missing...
Regards,
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jan 9, 2024, 1:15 AM EST
Hi Naveen,
Your image is missing !!!.
To change the values in a custom section in the app.config file, you need to follow these steps:
Locate the app.config file in your project. It is usually located in the root directory of your project.
Open the app.config file in a text editor or in Visual Studio.
Find the custom section you want to modify. Custom sections are defined in the
element and have a specific name and structure.Locate the section you want to modify and find the corresponding
element. This element defines the structure and properties of the custom section.Inside the
element, you will find the properties or elements that you want to change. Modify the values of these properties according to your requirements.Save the changes to the app.config file.
Here is an example of a custom section in the app.config file:
In this example, you can change the values of
Setting1andSetting2inside theelement.Remember to save the changes and rebuild your project for the modifications to take effect.
NaveenRank #6,081 · 277 reputationPosted Jan 9, 2024, 1:00 AM EST
Please check now.
NaveenRank #6,081 · 277 reputationPosted Jan 9, 2024, 1:18 AM EST
i am creating a windows form application
Amit MohantyRank #112 · 20K reputationPosted Jan 9, 2024, 1:23 AM EST
static void AddUpdateCustomSection(string key, string value) { try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = ((AppSettingsSection)configFile.GetSection("MyCustomSection")).Settings; if (settings[key] == null) { settings.Add(key, value); } else { settings[key].Value = value; } configFile.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (ConfigurationErrorsException) { Console.WriteLine("Error"); } }AddUpdateCustomSection("Key1", "Value123"); AddUpdateCustomSection("Key3", "Value3");