What you are looking for is the App.config
file. This is where you can store your connection string which can be altered for each environment:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Connection" value="127.0.0.1"/>
<add key="altConnection" value="L:\Path\To\Thing"/>
</appSettings>
</configuration>
You would obviously change the value=
within the <add key>
section of the XML/App.config file. This App.config can be stored somewhere with the program, that everyone has access to (if someone else has a better answer for deployment of a config file, feel free to edit this or comment below).
127.0.0.1 is just a default IP I used as an example
This can be used in code with adding using System.Configuration
and making sure you have the proper reference added to the project. The App.config can be accessed inline by using:
string conStr = ConfigurationManager.AppSettings["Connection"];
or something of the like. @Serge's comment is a great reference for getting started with App.config files!
For Deployment:
If you are deploying your program for a whole network, then I imagine a file share should work just fine (per @Elgonzo's comment). With this, you should be able to deploy to the file share, with the config file located there as well. Instead of giving your users copies of the .exe file, give them shortcuts to the .exe file. This will allow you to only have to update one location instead of many. If needed, the App.config can still be accessed, and each user should be able to use the program just fine. (This is how I deploy my applications within my network.)
Another option would be to have a Global Variable
that is asked for on each time the app is launched where they can enter in the IP address (or filePath) wanted depending on how you plan to go about deployment or how the environments are utilizing the program and for what.