繁体   English   中英

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

[英]C# how to access config file from another PC over the network

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

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; 
//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();

参考: 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM