Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ConfigurationManager.OpenExeConfiguration方法不支持';t返回键的值_C#_Wpf_Config_Configuration Files - Fatal编程技术网

C# ConfigurationManager.OpenExeConfiguration方法不支持';t返回键的值

C# ConfigurationManager.OpenExeConfiguration方法不支持';t返回键的值,c#,wpf,config,configuration-files,C#,Wpf,Config,Configuration Files,我正在使用ConfigurationManager.OpenExeConfiguration方法尝试从appSettings DynamicCali获取密钥。我已更新了文件DynamicCali,因此在更新后,我尝试打开它并获取新密钥的新值 例如: 在列表中,我的文件如下所示: <appSettings> <add key = "CZH" value = "Chezch Republic"/> <add key = "DEN" value = "Denmark"

我正在使用ConfigurationManager.OpenExeConfiguration方法尝试从appSettings DynamicCali获取密钥。我已更新了文件DynamicCali,因此在更新后,我尝试打开它并获取新密钥的新值

例如: 在列表中,我的文件如下所示:

<appSettings>
 <add key = "CZH" value = "Chezch Republic"/>
 <add key = "DEN" value = "Denmark"/>
</appSettings>

在某个时刻,我将向本节添加一个新的键/值对,它看起来如下所示:

 <appSettings>
     <add key = "CZH" value = "Chezch Republic"/>
     <add key = "DEN" value = "Denmark"/>
     <add key = "ITA" value = "Italy"/>
    </appSettings>

所以,在添加之后,我想得到新的值和它的键,但我看不到这样做的方法。我能得到的只是所有键,在那里一切正常,但我还想添加新键的值

我用Notepad++打开了我的文件,我可以看到它已正确更新,但我不知道如何获取新键的值

编辑:好的,我会再解释一遍,这次我真的希望没有人能理解我

使用ConfigurationManager.OpenExeConfiguration(指向文件的路径)我正在加载应用程序的配置文件。方法的返回类型为:配置 它的一个属性是AllKeys,当我调用它时,它会准确地返回我所需要的-所有更新的键,但是我不知道如何获取这些键的值。我想知道配置对象的是否有一个方法或属性(指向文件的路径)方法返回

这就是我的全部要求

 ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath
查看是否正在加载当前文件。否则,请使用自定义文件位置

 ConfigurationManager.OpenExeConfiguration("myfilepath.exe");

如果您正在动态添加、删除或更改appsettings。那么我建议您使用节上的属性。

在向app.config添加新值后尝试此操作

ConfigurationManager.RefreshSection(“appSettings”);
有关更多详细信息,请参阅文章:

试试这个:

Private Sub readsettings()
    Dim mySettings As NameValueCollection = ConfigurationManager.GetSection("ConnectionStrings")
    Dim i As Integer = 0
    While i < mySettings.Count
        Console.WriteLine("#{0} Key: {1} Value: {2}", i, mySettings.GetKey(i), mySettings(i))
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
End Sub
Private子读取设置()
将mySettings设置为NameValueCollection=ConfigurationManager.GetSection(“ConnectionString”)
尺寸i为整数=0
而我却不知道我的设置。数一数
Console.WriteLine(“#{0}键:{1}值:{2}”,i,mySettings.GetKey(i),mySettings(i))
System.Math.Max(系统线程联锁增量(i),i-1)
结束时
端接头

我已正确加载文件。我不是在寻找加载正确文件的方法。我只是在寻找获取appSettings部分中键值的方法。您需要刷新appSettings部分。
Private Sub readsettings()
    Dim mySettings As NameValueCollection = ConfigurationManager.GetSection("ConnectionStrings")
    Dim i As Integer = 0
    While i < mySettings.Count
        Console.WriteLine("#{0} Key: {1} Value: {2}", i, mySettings.GetKey(i), mySettings(i))
        System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
End Sub