日期:2014-05-17 浏览次数:20730 次
<configuration>
<connectionStrings>
<add name="connString" connectionString="xxxx"/>
</connectionStrings>
</configuration>
public class AppConfig
{
private XmlDocument Doc = new XmlDocument();
private AppDomain Ad = AppDomain.CurrentDomain;
public AppConfig()
{
Doc.Load(Ad.SetupInformation.ConfigurationFile);
}
public void LoadAppConfig()
{
Doc.Load(Ad.SetupInformation.ConfigurationFile);
}
public void SetAppValue(string key, string newValue)
{
Doc.SelectSingleNode("/configuration/appSettings/add[@key='" + key + "']").Attributes["value"].Value = newValue;
}
public void SaveAppConfig()
{
Doc.Save(Ad.SetupInformation.ConfigurationFile);
Doc.Load(Ad.SetupInformation.ConfigurationFile);
}
public string GetAppValue(string key)
{
return Doc.SelectSingleNode("/configuration/appSettings/add[@key='" + key + "']").Attributes["value"].Value;
}
}