Opening and Reading a Web.Config file for connectionstring

BlakeMcKenna

Active member
Joined
Oct 27, 2008
Messages
38
Programming Experience
10+
Can anyone show me a code snippent on how to open and read a Web.Config file and locate the connectionstring?

Thanks,
 
Do you mean a web site opening its own config file or a program opening a config file for any web site? If it's the former, the WebConfigurationManager class has an AppSettings property and a ConnectionStrings property, both of which can be indexed by key to get the corresponding value. If it's the latter, the same class can be used to open a specific config file and return a Configuration object, which also has the two aforementioned properties.
 
Back
Top