0

I want to Access configuration file from another computer example.

string location = @"\\SERVER\Shared\Ramgy\Settings.config"

// get server from **SERVER** location
this.txthostname.Text = Properties.Settings.Default.server; 

// get port from the SERVER location
this.txtport.Text = Properties.Settings.Default.port; 

//get username from the SERVER location
this.txtusername.Text = Properties.Settings.Default.username;

// get password from the SERVER location
this.txtpassword.Text = Properties.Settings.Default.password;

// get database from the SERVER location
this.txtdatabase.Text = Properties.Settings.Default.database; 
Ramgy Borja
  • 2,330
  • 2
  • 19
  • 40

1 Answers1

1
//Reading a Dlls own config:
var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
var location = executingAssembly.Location; //C:\MyApp\bin\Debug\Search.dll

//Read a colleagues config file (the settings.settings are stored in config):
location = "\\JoeBlogsPC\c$\AppPath\Search.dll";

var config = ConfigurationManager.OpenExeConfiguration(location);
var sections = config.Sections;
string s = config.AppSettings.Settings["Something"].Value.ToString();

Ref: https://stackoverflow.com/a/15726277/495455
Ref: https://stackoverflow.com/a/9763947/495455


If you get stuck with ConfigurationManager.OpenExeConfiguration try System.Xml.Linq instead

https://stackoverflow.com/a/42939187/495455


Another way to load a specific exe configuration file:

ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = "EXECONFIG_PATH" };
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); 

Ref: https://stackoverflow.com/a/12587078/495455

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • 1
    all I want is to access this connection `string location = @"\\SERVER\Shared\Ramgy\Settings.config";` and extract server,port, username etc. thanks – Ramgy Borja Aug 29 '17 at 02:55
  • 1
    `string s = config.AppSettings.Settings["Something"].Value.ToString();` Object reference not set to an instance of an object. – Ramgy Borja Aug 29 '17 at 03:20