2

I created in my C# Project in VS an Application Configuration File. If Im compiling and creating the .exe I get the config file into the same folder. Thats fine. I just dont want the name MyApp.exe.config. I would like to set the file extension to .xml, maybe MyApp.exe.config.xml - is there a way to do this?

With .xml people could use tools like notepad++ and the xml syntax highlight would be automatically there.

miri
  • 1,611
  • 5
  • 20
  • 24
  • 1
    Your question leads me to my: Who and why should someone edit the app.config file manually? User configuration options can ad should be handled in another way. – DanielB Aug 23 '12 at 09:39
  • It does not matter. you can use notepad++ to open config file with syntax highlighted – cuongle Aug 23 '12 at 09:39
  • @DanielB Lets say you have a program that is upload some stuff on a server. You could add address, user, pass... and so on to the config file. Now let say the server adress changed, you dont want to compile your code again, right? :) So you just have to change the app.config. Thats how I thought. Or is there a smarter way to do this? – miri Aug 23 '12 at 09:41
  • Possible [duplicate](http://stackoverflow.com/questions/6341906/read-custom-configuration-file-in-c-sharp-framework-4-0) – Jacob Seleznev Aug 23 '12 at 09:41
  • @CuongLe You can open the file. But you have to set manually the xml highlight, because the extension ".config" is unknown for notepad++. But notepad++ was just an example, there are other tools and yes you can open it with all of them. Its just easier for the other users if its .xml – miri Aug 23 '12 at 09:43
  • @miri: If the user is responsible for setting a custom server, because the server has nothing to do with your application (like in a FTP client) then you should give the user an option within your application to change that setting. If you are responsible for the server (ie. using an own webservice from within your app) you should provide an update to your application. This update can only include the new app.config if if doesn't need a new compile. – DanielB Aug 23 '12 at 09:46
  • @DanielB: think about app.config as about an **administrative** settings store, not a **user** settings store. It is not common - to distribute some kind of administrative tool, ofter there's no resources (time, money, people) to do that, or there's no need to do that because of settings simplicity. – Dennis Aug 23 '12 at 09:58

1 Answers1

3

You can change the config file:

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "[path]/MyApp.exe.config.xml");

With this you can also share config files between different applications.

Asken
  • 7,679
  • 10
  • 45
  • 77