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 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Don't forget u will need to add a reference to 'System.Configuration'.
This is an XML of my other app. How do I load it into ConfigurationManager?