app-config

ConfigurationManager doesn't save settings

旧城冷巷雨未停 提交于 2019-11-26 19:03:43
Here is the code I'm using: private void SaveConfiguration() { if (txtUsername.Text != "" && txtPassword.Text != "") { ConfigurationManager.AppSettings["Username"] = txtUsername.Text; ConfigurationManager.AppSettings["Password"] = txtPassword.Text; MessageBox.Show("Su configuracion guardo exitosamente.", "Exito!"); this.Close(); } else { MessageBox.Show("Por favor lleno los campos.", "Error."); } } Now, the settings are persisted but when I close the application and press F5 to run it again, the values are reverted to what is typed into the app.config file. Any suggestions? il_guru I think you

Variables within app.config/web.config

烂漫一生 提交于 2019-11-26 18:37:16
Is it is possible to do something like the following in the app.config or web.config files? <appSettings> <add key="MyBaseDir" value="C:\MyBase" /> <add key="Dir1" value="[MyBaseDir]\Dir1"/> <add key="Dir2" value="[MyBaseDir]\Dir2"/> </appSettings> I then want to access Dir2 in my code by simply saying: ConfigurationManager.AppSettings["Dir2"] This will help me when I install my application in different servers and locations wherein I will only have to change ONE entry in my entire app.config . (I know I can manage all the concatenation in code, but I prefer it this way). Arjan Einbu Good

.net dynamically refresh app.config

我只是一个虾纸丫 提交于 2019-11-26 18:13:25
问题 How do I dynamically reload the app.config in a .net Windows application? I need to turn logging on and off dynamically and not just based upon the value at application start. ConfigurationManager.RefreshSection("appSettings") does not work and I've also tried explicitly opening the config file using OpenExeConfiguration but I always get the cached value at application startup and not the current value. I've accepted the answer of creating a custom configuration section. As a side note and

How do I set CultureInfo.CurrentCulture from an App.Config file?

喜夏-厌秋 提交于 2019-11-26 17:47:04
问题 I need to set my application's culture through an App.Config file, so that "pt-BR" is used automatically for parsing dates without the need to manually inform the culture for each operation. As far as I know, there's a globalization section that can be defined inside the system.web section in a Web.Config file, but I'm running a console application and I can't figure this out. Any idea? 回答1: I don't know a built-in way to set it from App.config, but you could just define a key in your App

Use XML includes or config references in app.config to include other config files' settings

微笑、不失礼 提交于 2019-11-26 17:24:38
I have standard logging, NHibernate, etc. configuration blocks in my app.config and I'd like to extract them into a common XML file that can be included as a reference by all of my applications' app.config files. Is this possible? Yes, you can use the configSource attribute of the configuration block. All configuration blocks have this attribute - although it isn't documented. See this article , all the way at the bottom, appendix B. I've also pasted the relevant section below: Appendix B: including external configuration files Despite all the greatness to be found in .NET 2.0's configuration

How to find path of active app.config file?

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:03:56
问题 I'm trying to finish this exception handler: if (ConfigurationManager.ConnectionStrings["ConnectionString"]==null) { string pathOfActiveConfigFile = ...? throw new ConfigurationErrorsException( "You either forgot to set the connection string, or " + "you're using a unit test framework that looks for "+ "the config file in strange places, update this file : " + pathOfActiveConfigFile); } This problem seems to only happen to me when I'm using nUnit. 回答1: Try this AppDomain.CurrentDomain

Relocating app.config file to a custom path

心不动则不痛 提交于 2019-11-26 14:29:32
Is it possible to relocate the whole App.Config file to a custom path? It seems a bit odd that the config file resides in the same folder as the exe, with Windows' new approcah of saving all program settings in c:\ProgramData and all. An additional requirement we have is to programatically specify where to find the app.config file. The reason for this being that we spawn different service instances from the same exes, and would like to store each service's app.config in that service's settings folder under c:\ProgramData\\. Each AppDomain has/can have its own configuration file. The default

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

爱⌒轻易说出口 提交于 2019-11-26 14:12:50
This question already has an answer here: Custom app.config Config Section Handler 3 answers I want to add a custom configuration section in my app.config file. Is there a way to do it and how can I access these settings in my program. Following is the config section I want to add to my app.config : <RegisterCompanies> <Companies> <Company name="Tata Motors" code="Tata"/> <Company name="Honda Motors" code="Honda"/> </Companies> </RegisterCompanies> Jan Remunda Import namespace : using System.Configuration; Create ConfigurationElement Company : public class Company : ConfigurationElement {

Changing App.config at Runtime

孤街醉人 提交于 2019-11-26 14:09:31
问题 I'm writing a test WinForms / C# / .NET 3.5 application for the system we're developing and we fell in the need to switch between .config files at runtime, but this is turning out to be a nightmare. Here's the scene: the WinForms application is aimed at testing a WebApp, divided into 5 subsystems. The test process works with messages being sent between the subsystems, and for this process to be successful each subsystem got to have its own .config file. For my Test Application I wrote 5

Is there any way for an App.config file to reference another full config file? (.NET)

╄→гoц情女王★ 提交于 2019-11-26 13:53:54
问题 Update: this question, including the title, was rephrased, see history for details I know that the following App.config includes a external file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings configSource="appSettings.config"/> <system.net> <connectionManagement> <add address="*" maxconnection="50"/> </connectionManagement> </system.net> </configuration> But I don't know how to move the system.net to the second file. Actually I haven't tried it, but I am almost certain