| Author |
dll read config file
|
|
|
| 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
| |
| Brock Allen 2005-09-29, 7:01 pm |
| 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
> 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
>
| |
|
| I know appSettings will work from a asp.net app but what about a dll that is
not included in the asp.net project?
"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:b8743b1131f688c7933655903438@msnews
.microsoft.com...
> 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
>
>
>
| |
| Lucas Tam 2005-09-29, 7:01 pm |
| "NuB" <csharpcoder@optonline.net> wrote in
news:OetqYXRxFHA.3772@TK2MSFTNGP11.phx.gbl:
> 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.
--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
| |
|
| 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?
"Lucas Tam" <REMOVEnntp@rogers.com> wrote in message
news:Xns96E085B4C171Fnntprogerscom@127.0.0.1...
> "NuB" <csharpcoder@optonline.net> wrote in
> news:OetqYXRxFHA.3772@TK2MSFTNGP11.phx.gbl:
>
>
> 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.
>
> --
> Lucas Tam (REMOVEnntp@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
| |
| Lucas Tam 2005-09-29, 7:01 pm |
| "NuB" <csharpcoder@optonline.net> wrote in
news:ez6LpnRxFHA.2232@TK2MSFTNGP11.phx.gbl:
> 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).
--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
| |
|
| 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?
"Lucas Tam" <REMOVEnntp@rogers.com> wrote in message
news:Xns96E08E49D4692nntprogerscom@127.0.0.1...
> "NuB" <csharpcoder@optonline.net> wrote in
> news:ez6LpnRxFHA.2232@TK2MSFTNGP11.phx.gbl:
>
>
> 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).
>
> --
> Lucas Tam (REMOVEnntp@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
| |
|
| 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
"Lucas Tam" <REMOVEnntp@rogers.com> wrote in message
news:Xns96E08E49D4692nntprogerscom@127.0.0.1...
> "NuB" <csharpcoder@optonline.net> wrote in
> news:ez6LpnRxFHA.2232@TK2MSFTNGP11.phx.gbl:
>
>
> 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).
>
> --
> Lucas Tam (REMOVEnntp@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
| |
| Lucas Tam 2005-09-29, 7:01 pm |
| "NuB" <csharpcoder@optonline.net> wrote in
news:#AgxsRSxFHA.2072@TK2MSFTNGP14.phx.gbl:
> 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.
--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
| |
| Brock Allen 2005-09-29, 7:01 pm |
| An assembly can access the application's config file. What do you mean by
"not included in the asp.net project"?
-Brock
DevelopMentor
http://staff.develop.com/ballen
[color=darkred]
> I know appSettings will work from a asp.net app but what about a dll
> that is not included in the asp.net project?
>
> "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
> news:b8743b1131f688c7933655903438@msnews
.microsoft.com...
>
| |
|
| 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
"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:b8743b113266d8c793670b33173a@msnews
.microsoft.com...
> An assembly can access the application's config file. What do you mean by
> "not included in the asp.net project"?
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
|
|
|
|