dll read config file

N

NuB

I'm creating a C# class file(DLL) that will be used by an asp.net
application. In the DLL I want to read a web.config, or app.config file so
some information can change without having to go into the code itself. How
can I have the dll read a app.config or web.config file for data?

The information I'm looking to store in the file is servernames, file
locations, etc.


thanks
 
B

Brock Allen

Check out <appSetings> and the System.Configuration.ConfigurationSettings
class for v1.x. Other than that, there's no good way to read the config file
(other than manual XML parsing). In v2.0 there's a proper API for reading
the settings via System.Configuration.ConfigurationManager.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
N

NuB

I know appSettings will work from a asp.net app but what about a dll that is
not included in the asp.net project?
 
L

Lucas Tam

I'm creating a C# class file(DLL) that will be used by an asp.net
application. In the DLL I want to read a web.config, or app.config
file so some information can change without having to go into the code
itself. How can I have the dll read a app.config or web.config file
for data?

Use the standard methods for accessing the configuration file:

System.Configuration.ConfigurationSettings.AppSettings.Item("MyKey")

When you instantiate your DLL in a ASP.NET project, it will have access the
the web.config.

When you instantiate your DLL in a VB.NET project, it will have access the
the app.config.
 
N

NuB

i want a seperate config file for the dll, in case the dll is going to used
by another type of project such as a windows app. Right now its being
designed for a asp.net web app, but that could change in the future.

Could I create an XML file and read the tags in that for my information, and
if so how would i do that?
 
L

Lucas Tam

i want a seperate config file for the dll, in case the dll is going to
used by another type of project such as a windows app. Right now its
being designed for a asp.net web app, but that could change in the
future.

Could I create an XML file and read the tags in that for my
information, and if so how would i do that?

No need to create a separate config file - the way you read the config file
is the same for both ASP.NET and VB.NET projects. The DLL will work in both
ASP.NET and VB.NET projects (as long as you use the System.Configuration
classes.

The DLL will switch "files" depending on the context it is loaded (i.e.
ASP.NET or VB.NET).
 
N

NuB

So in my web.config file for the asp.net web app I'm creating, if I have a
key named server and the actual asp.net file does not use that key I can
read it from the DLL I'm creating?
 
N

NuB

also to note: this is a separate project DLL (class). I did not add a class
to an existing asp.net web application. I created a seperate project which
is just this DLL file I want to use
 
L

Lucas Tam

So in my web.config file for the asp.net web app I'm creating, if I
have a key named server and the actual asp.net file does not use that
key I can read it from the DLL I'm creating?


I believe your DLL will read keys from the web.config.

Not sure if you can have a DLL config AND a Web.config.
 
N

NuB

its a seperate project. I created a new project which is the dll I'm
creating. This dll can be used by either an asp.net project or a windows
application.

I didn't add a Class to an existing asp.net project, it is own project
 

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

Top