473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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.
--

fiddlewidawiddum
Nov 16 '06 #1
5 18484
On Thu, 16 Nov 2006 samuelhon <sa****@gmail.comwrote:
You can try this:

http://www.informit.com/articles/art...&seqNum=5&rl=1
unfortunately I can't seem to use Server.Mappath with the dll...

--

fiddlewidawiddum
Nov 16 '06 #3
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.
On Thu, 16 Nov 2006 12:45:40 +0100, Stimp <re*@spumco.comwrote:
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.


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '06 #4
Indeed.

If you are using the .NET 1.1 Framework

connstr=ConfigurationSettings.AppSettings["constring"] will do the job.
--
Bits. Bytes.
http://bytes.thinkersroom.com
------------------------------
"Morten Wennevik" wrote:
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.
Nov 16 '06 #5
Include System.Web in your dll and try using HttpContext.Current.Server.Mappath

"Stimp" wrote:
On Thu, 16 Nov 2006 samuelhon <sa****@gmail.comwrote:
You can try this:

http://www.informit.com/articles/art...&seqNum=5&rl=1

unfortunately I can't seem to use Server.Mappath with the dll...

--

fiddlewidawiddum
Nov 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tony Jones | last post by:
Is it possible for me to create a class library DLL and have it read it's configuration settings from the web.config of the ASP.NET application referencing it? IE - if I call...
3
by: ad | last post by:
I have a web application and a class library in a solution. The class library is make of typed datasets, and include many Table in it. The connection strings of the TableAdapters is come from...
1
by: Serdge Kooleman | last post by:
Could i access Web.Config in Class Library? Next line work fine in web project that consist Web.config: strConnString =...
3
by: Martyn Fewtrell | last post by:
Hi there. First of all let me apologise for this is a somewhat general question to which I would be interested in any opinions. As far as I can see when I create a web application the...
8
by: Mihai Velicu | last post by:
Hi ! I created a class library and in it I have a class that call "ConfigurationManager" to find out what type of database I work and the connection string.When I call this class from a form,...
2
by: Maxwell2006 | last post by:
Hi, As far as I know, a class library project cannot have any app.config dedicated to itself and it always depends on the main application to provide the .config settings. Based on above, I...
3
by: ThazKool | last post by:
No matter what I do the external class library DLL is added back to the bin folder. I have tried to remove this on the server, in vss, and in the "Temporary ASP.NET Files" folders to no avail. ...
2
by: Steve | last post by:
I want to call my web service from a class library and have that library handle all the wse stuff, so that applications using that library don't have to worry about it. Is that possible? I've...
7
by: Peter Bradley | last post by:
OK. A bit behind the times, I know; but we're just moving over to .NET 2.0. How on earth do you manage configuration settings in a class library in .NET 2.0? In version 1.1, we used a handy class...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.