xml - Using config file in public class -
xml - Using config file in public class -
is possible to load config file, contains server connection, using class constructor , storing in public static string. example,
config.xml
<config> <connstring> "server=...; user id =...; user pass=...; database=...";</connstring> </config>
code:
namespace connection.settings { public class settings { public settings() { xmldocument cfg = new xmldocument(); cfg.load("config.xml"); connection = cfg.selectsinglenode("/config/connstring").innertext; } public static string connection; public string connection { { homecoming connection; } } public static string connectionstring = connection; } }
the reason doing connection shared many apps , yet alter connection in xml file without need touch applications.
yes it's possible. appconfig mutual place store connection strings it's not required. long applications can access file want store in used mutual source different configuration settings.
i didn't seek code illustration like:
var conf = xdocument.load(filenamehere.xml); var connection = (from c in conf.decendents("config") select c.element("connstring")).singleordefault();
should recover setting xml.
xml class config
Comments
Post a Comment