-1

I am needing to find away to write to another programs app.config file.

we have a 3rd party application that gets some values from an AppSettings section in its own config. but the only way we can get to change the value is when we call the application and once it runs it does a function which we don't want it to do if it doesn't have the correct values.

We need to encrypt one of the values so what we were think of was creating an application that would save the values in this 3rd party app.config.

saving the values and the encryption aren't a problem its doing it in another applications config file.

Is there a way to set which config file we use or a config path setting?

Regards

Aidan

Aidan
  • 27
  • 6
  • 2
    The fact it's a `.config` file is throwing you off a bit. Whether it's `.config` or a `.txt` the principles of reading/writing a file are the same. https://support.microsoft.com/en-us/kb/816149 –  Oct 01 '15 at 12:56
  • @toadflakz - that's not a duplicate, OP wants to write to a file. –  Oct 01 '15 at 12:57
  • Further to my previous comment, permissions may be an issue (of course), but again - this shouldn't be any different to any other that may require permissions or be in use. –  Oct 01 '15 at 13:00
  • Wrong post - actually a duplicate of http://stackoverflow.com/questions/1357240/change-the-value-in-app-config-file-dynamically ... which shows how to open, edit and save another executables .config file. – toadflakz Oct 01 '15 at 13:10
  • Hi thanks for the comments if its just like reading it like a normal text file and then changing the values then i will try and do that i just didn't know if there was a way to set the config path so 2 applications would use the same config file. – Aidan Oct 01 '15 at 13:12

1 Answers1

0

Thank you for the help with this, I managed to get it done through this code.

 string configLocation = string.Format("{0}\\APP.exe.config", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
 ExeConfigurationFileMap map = new ExeConfigurationFileMap();
 map.ExeConfigFilename = configLocation;
 Configuration config =  ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
 txtEndpoint.Text = config.AppSettings.Settings["ENDPOINT"].Value;

This now allows me to write out the set config file values in the appsettings.

Cheers All.

Aidan

Aidan
  • 27
  • 6