0

For c# applications (windows apps), Is it possible to insert an external configuration file to keep the connection strings (a common config file to hold the connection strings). I know that can be done for config files which are in the same folder (or in child folders I gess). But I want that common config (which has connectionString node) to be in the parent folder. And at the same time I need to use the same code to read the connection strings.

I have a folder and files structure like this

Parent Folder
--> common.connections.config
      --> Folder 1 (App1.exe)
                 --> App1.exe.config
        --> Folder 2 (App2.exe)
                  --> App2.exe.config

Can anyone help please..

Nlr
  • 183
  • 3
  • 13
  • 2
    [Maybe this will be of help](http://stackoverflow.com/questions/1838619/relocating-app-config-file-to-a-custom-path), but I would suggest you be careful when relying on parent folder locations - If the application moves, it won't work anymore – musefan Oct 03 '13 at 09:25
  • Yes your point is true. But my scenario is that, I have a folder (patent) which has several sub folders, with different utilities inside. I am certain this parent child folder structure remains the same. All the utilities in the these sub folders need to get this common connection strings (and also they have there own as well). your link help full. but I would like to do without code change. – Nlr Oct 03 '13 at 11:47

1 Answers1

0

By default the config file has the be the same name as the app calling it and is in the same folder, this means that if you write a DLL then any config setting for it need to be added to the calling applications config,

if you want to do anything else you will need to manually process the config file, and doing that means you can do what ever you want with it

website behavior is a little different, but you aren't asking about that

MikeT
  • 5,398
  • 3
  • 27
  • 43
  • additionally the generated code that reads the config file also has default values stored in it, so if the config file is missing entirely it falls back on the coded defaults, hiding the fact it can't locate the config – MikeT Oct 03 '13 at 10:15