3

Is there an easier way of doing the lines below?

var doc = new XmlDocument();
doc.Load("../../../MyWebSite/Web.config");
var mysqlconn = doc.DocumentElement.SelectSingleNode(
    "//appSettings//add[@key='mysqlconn']").Attributes["value"].Value;

1 Answers1

11
System.Configuration.ConfigurationManager.AppSettings["mysqlconn"]

Should give you the value. You may want to move them into a <connectionStrings /> section, which you can use:

System.Configuration.ConfigurationManager.ConnectionStrings["mysqlconn"]
                                                                .ConnectionString
Abdusalam Ben Haj
  • 5,343
  • 5
  • 31
  • 45
Steven V
  • 16,357
  • 3
  • 63
  • 76