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

时间:2017-11-23 06:21:13

标签: 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); 

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

1 个答案:

答案 0 :(得分:1)

使用此代码:

        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();
相关问题