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

  • Thread starter Thread starter Stimp
  • Start date Start date
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.
 
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.
 
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

Back
Top