views:

69

answers:

2

Hi, I have an app.config file for a windows service which includes database connection strings and appsettings. when I install the windows service, it gets installed in "C:\program files\" folder and the settings are copied to a file called ".exe.config" in the same folder, which makes it difficult to change the settings after it is deployed to test environment. can I have all settings stored in an external file somewhere on shared network drive, instead of the same folder where the service is installed? is that possible? only alternative I can think of is to create an xml file and read it using the .NET XML API, another issue is I need to watch for the changes in the file and reload the settings in the service.

A: 

Linq to XML makes it fairly easy to read an external settings file. You can also use a FileSystemWatcher to watch for changes in the settings file.

Venemo
A: 

You can push some of your config settings out of your core config file, e.g.:

<connectionStrings configSource="connectionStrings.config" />

And:

<?xml version="1.0" encoding="UTF-8"?>
<connectionStrings>

</connectionString>

That way, as long as you don't deploy the connectionStrings.config file, you can safely deploy the app and maintain those settings separately. The good thing about this approach, is you don't need to create a whole new method of getting config data, this is built into the configuration system, just read these settings how you do currently.

Matthew Abbott