1

I have done my application in Visual Studio 2017. It's all great, works perfect, but now I want to make that flexible to use that in other environments.

I have 3 or 4 different environment and all of them have their own local network with server.

I need to make my application ask for settings for the first time on a computer in that network (to enter a connection string).

After installing on that computer, these settings should be stored somewhere, but be available to other users in that network (the next installation does not require a setup on a computer, but uses the data for threads.

I have no idea how to do that, I read about App.config but don't see nothing useful there.

Any idea?

stuartd
  • 70,509
  • 14
  • 132
  • 163
  • 2
    https://stackoverflow.com/questions/2400097/reading-from-app-config-file – serge Nov 16 '18 at 16:33
  • 2
    "_these settings should be stored somewhere, but be available to other users in that network_" Use a file share, perhaps? –  Nov 16 '18 at 16:41
  • _"I have 3 or 4 different environment and all of them have their own local network with server"_ - so the first run has to write the data to the server? – stuartd Nov 16 '18 at 16:41
  • Yes, first run have to do that. – Aleksa Djuric Nov 16 '18 at 16:47
  • also, you can have a look on this tutorial https://www.youtube.com/watch?v=atFsLc2wstw – serge Nov 16 '18 at 16:52
  • @elgonzo What you mean on file share? – Aleksa Djuric Nov 16 '18 at 16:53
  • Are you asking what a file share is? –  Nov 16 '18 at 16:58
  • @elgonzo I know in theory what is, but how you mean to use that for this? If you didn't understand good, I need to use one settings for all PCs in one local network ( environment ). All other environments have their own settings. – Aleksa Djuric Nov 16 '18 at 17:04
  • 3
    Create a file share with appropriate permissions(!) on a computer/device/server in the LAN, put your config file on it, and all other computers in the same LAN should be able to acess this file. That's all... –  Nov 16 '18 at 17:06
  • @elgonzo I understand now, thank you – Aleksa Djuric Nov 16 '18 at 17:27
  • I was just reading this: https://www.theinquirer.net/inquirer/news/3066503/microsoft-wont-fix-the-network-mapping-borkage-in-windows-10-until-2019, and perhaps i shouldn't have suggested file shares. At least not when there is a chance that machines with the infamous OS code-named "Relentless Borkage" are involved... –  Nov 17 '18 at 00:00

1 Answers1

0

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.

Jaskier
  • 1,075
  • 1
  • 10
  • 33
  • thank you for answering. I see what you mean with App.config , but main problem here for me is when I need to install that on second PC and after that... So i wrote all on first installation in App.config , but how to access that later? Because I have one .exe file only – Aleksa Djuric Nov 16 '18 at 16:56
  • 1
    Thanks, I think it will be enough for me, sounds good and practical. – Aleksa Djuric Nov 16 '18 at 17:26