C# 如何通过网络从另一台 PC 访问配置文件



我想从另一台计算机示例访问配置文件。

string location = @"\SERVERSharedRamgySettings.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; 
//Reading a Dlls own config:
var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
var location = executingAssembly.Location; //C:MyAppbinDebugSearch.dll
//Read a colleagues config file (the settings.settings are stored in config):
location = "\JoeBlogsPCc$AppPathSearch.dll";
var config = ConfigurationManager.OpenExeConfiguration(location);
var sections = config.Sections;
string s = config.AppSettings.Settings["Something"].Value.ToString();

编号: https://stackoverflow.com/a/15726277/495455
编号: https://stackoverflow.com/a/9763947/495455


如果您遇到ConfigurationManager.OpenExeConfiguration请尝试System.Xml.Linq

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


加载特定 exe 配置文件的另一种方法:

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

参考: https://stackoverflow.com/a/12587078/495455

最新更新