PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.

dll read config file

 
 
NuB
Guest
Posts: n/a
 
      29th Sep 2005
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


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      29th Sep 2005
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
>



 
Reply With Quote
 
 
 
 
NuB
Guest
Posts: n/a
 
      29th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>>

>
>



 
Reply With Quote
 
Lucas Tam
Guest
Posts: n/a
 
      29th Sep 2005
"NuB" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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 ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
 
Reply With Quote
 
NuB
Guest
Posts: n/a
 
      29th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:Xns96E085B4C171Fnntprogerscom@127.0.0.1...
> "NuB" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> 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 ((E-Mail Removed))
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com



 
Reply With Quote
 
Lucas Tam
Guest
Posts: n/a
 
      29th Sep 2005
"NuB" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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 ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
 
Reply With Quote
 
NuB
Guest
Posts: n/a
 
      29th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:Xns96E08E49D4692nntprogerscom@127.0.0.1...
> "NuB" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> 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 ((E-Mail Removed))
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com



 
Reply With Quote
 
NuB
Guest
Posts: n/a
 
      29th Sep 2005
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" <(E-Mail Removed)> wrote in message
news:Xns96E08E49D4692nntprogerscom@127.0.0.1...
> "NuB" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> 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 ((E-Mail Removed))
> Please delete "REMOVE" from the e-mail address when replying.
>
> Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com



 
Reply With Quote
 
Lucas Tam
Guest
Posts: n/a
 
      29th Sep 2005
"NuB" <(E-Mail Removed)> wrote in
news:#(E-Mail Removed):

> 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 ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.

Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      29th Sep 2005
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

> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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
>>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner Microsoft ASP .NET 0 9th Apr 2007 10:00 PM
DTDs for machine.config, web.config, security.config available ? =?Utf-8?B?UGF1bCBLZW5uZWR5?= Microsoft Dot NET Framework 1 5th Feb 2007 06:42 AM
app.config and assembly config in My.Config =?Utf-8?B?QmFydA==?= Microsoft Dot NET Framework 8 7th Sep 2006 06:19 AM
using ReadXml to read exe.config file into Grid and update the exe.config using WriteXml hazz Microsoft C# .NET 0 7th Jul 2006 10:32 PM
Web References how to config to read URL from config? Bob Microsoft ASP .NET 7 5th May 2004 04:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:23 PM.