C#写配置文件,在程序运行时查看配置文件有字段,但是退出程序后配置文件该字段又为空了,这个怎么回事? 20
代码:stringstr=txtMusic.Text;//写配置System.Configuration.Configurationconfig=Configuratio...
代码:
string str = txtMusic.Text;
//写配置
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["backMusic"].Value = str;
//config.Save(ConfigurationSaveMode.Modified);
//ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
config.Save(ConfigurationSaveMode.Modified);
配置文件:<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<appSettings>
<add key="backMusic" value=""/>
</appSettings>
</configuration> 展开
string str = txtMusic.Text;
//写配置
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["backMusic"].Value = str;
//config.Save(ConfigurationSaveMode.Modified);
//ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
config.Save(ConfigurationSaveMode.Modified);
配置文件:<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<appSettings>
<add key="backMusic" value=""/>
</appSettings>
</configuration> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询