Reputation: 11
I have a C# .net 3.5 console app that needs to programatically open up 50 website folders (on the same server) open their root web.config and get the dbname, user, password.
I know how to do this on a single site opening it's own local web.config How to get Connection String From the Web.config
But how can a console app load external ones?
Would it be like this:
ConfigurationFileMap fileMap = new ConfigurationFileMap(site-root-path + "/Web.Config");
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
configuration.ConnectionStrings["storeConn"].ConnectionString;
Upvotes: 1
Views: 1015
Reputation: 4922
A web config file is just an XML file so you can use any XML parser such as Linq to XML and then navigate to the ConnectionStrings node.
Upvotes: 1