-1

我正在尝试读取另一个应用程序 (app.exe.config) 的配置文件中的应用程序设置。

我已经尝试了几件事。最近我用这个:

        System.Configuration.Configuration config =
          ConfigurationManager.OpenExeConfiguration(FullPath() + ".config");

        // Get the AppSetins section.
        AppSettingsSection appSettingSection = config.AppSettings;

        // Display raw xml.
        Debug.WriteLine(appSettingSection.SectionInformation.GetRawXml());

但 GetRawXml() 什么也不返回。我哪里错了?FullPath() 方法返回正确的路径,我已经测试过了。

4

2 回答 2

1

配置文件是有效的 xml 文件,因此您也可以XElement.Load(filepath)根据需要尝试使用和处理 xml 树。

var appSettingsRawXml = System.Xml.Linq.XElement.Load(FullPath() + ".config")
    .Element("appSettings")
    .ToString();
于 2013-08-12T09:51:59.893 回答
0

GetRawXml支持 .NET Framework 基础结构,并且不打算直接从您的代码中使用。MSDN

于 2013-08-12T09:44:12.540 回答