c# - 如何打开另一个应用程序的配置文件

标签 c# xml c#-4.0 configuration config

我的应用程序的另一个文件夹中存在一个配置文件(.exe)。当我运行应用程序时,我想打开该文件,然后在 appsetting 中编辑一些更改。我可以使用

获取 .exe 文件的路径
string directory1 = 
System.IO.Directory.GetParent(Environment.CurrentDirectory).ToString(); 
string directory2 = @"DualPort\SGPMService.UI.exe";
string path1 = Path.Combine(directory1, directory2);

现在我无法加载配置文件。我尝试使用 xmldocumentfilestream 两者。

XmlDocument d = new XmlDocument();
d.Load(path1);
FileStream fileStream = new FileStream(path1, FileMode.Open); 

加载文件和编辑更改的正确方法是什么?

最佳答案

使用此代码:

        var config = ConfigurationManager.OpenExeConfiguration("xxx.exe");
        // get value
        var item1 = config.AppSettings.Settings["akey"].Value;
        // set value
        config.AppSettings.Settings["akey"].Value = value;
        config.Save();

关于c# - 如何打开另一个应用程序的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47448849/

相关文章:

java - java如何解析XML文件

linq - 如果找到多个实例则返回 null

C#格式化字符串日期

c# - 解释 NetCore 上 C# TcpClient/TcpListener 的奇怪行为

c# - 如何输出以控制 bool 值?

使用包含 slice 的结构时 xml 恶作剧?

java - 如何回滚android studio中的更改?

c# - HttpContext.Current.User.Identity.IsAuthenticated 在登录控件 LoggedIn 事件中为 false

c# - 基于另一个 DropDownList 填充 DropDownList(层叠下拉)

c# - 如何正确声明类变量(CUIT 控件)