how to refer to web.config from external class library dll?

S

Stimp

I've created a dll that I placed in my web application's 'bin'
directory.

I want to access the web.config file from this dll so that I can
retrieve a node value.

e.g.

Dim oDoc As XmlDocument = New XmlDocument

oDoc.Load("../web.config")

sOutput = oDoc.SelectSingleNode("//constring").Value


but it searches for the file in the system32 folder (or windows folder
in this case)

How can I get it to retrieve the file that is in the subdirectory?

thanks.
 
M

Morten Wennevik

Hi Stimp,

If you need to read some of the settings in web.config you can use

string value = ConfigurationManager.AppSettings[key]; // for appsettings
values
string value = ConfigurationManager.ConnectionStrings[key]; // for
connection strings

This works for all code running in the web application, including external
libraries.
For further info on how to read web.config check out the
System.Configuration namespace.
 
G

Guest

Indeed.

If you are using the .NET 1.1 Framework

connstr=ConfigurationSettings.AppSettings["constring"] will do the job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top