我在项目里添加一个App.config配置文件,里面的代码如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="connectionstring" value="User ID=sa;Data Source=.;
Password=;Initial Catalog=test;Provider=SQLOLEDB.1;" />
<add key="TemplatePATH" value="Template" />
</appSettings>
</configuration>
我现在在窗体 Form1里面 如何去读取这个配置文件的属性呢,
我已经引用命名空间using System.Collections;
就打个比方去读取这个配置文件value的属性吧,谢谢.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="connectionstring" value="User ID=sa;Data Source=.;
Password=;Initial Catalog=test;Provider=SQLOLEDB.1;" />
<add key="TemplatePATH" value="Template" />
</appSettings>
</configuration>
我现在在窗体 Form1里面 如何去读取这个配置文件的属性呢,
我已经引用命名空间using System.Collections;
就打个比方去读取这个配置文件value的属性吧,谢谢.
private void button1_Click(object sender, EventArgs e)
{
string ss = ConfigurationManager.AppSettings["keyname"];
MessageBox.Show(ss);
}
这样子写的
结果呢 报如下错误
错误 1 当前上下文中不存在名称“ConfigurationManager” D:\测试\加app配置文件\加app配置文件\Form1.cs 72 25 加app配置文件
否则就用
ConfigurationSettings.AppSettings[“keyname”];
看来你用的是.net3.5+
public static bool RegEdit(Hashtable Ht)
{
if (Ht.Count > 0)
{
Configuration C = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
foreach (DictionaryEntry s in Ht)
{
C.AppSettings.Settings[s.Key.ToString()].Value = s.Value.ToString();
}
C.Save();
}
return true; }
public static string GetReg(string Key)
{
Configuration C = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
return C.AppSettings.Settings[Key].Value;
}
{
其中的Hashtable 是什么呢