Hi,
I have a question about the app.config file. I am using EnterpriseLibrary
v3.1.

1) From what I read on this forum, I can only have 1 app.config file in my
windows application. One of my dll projects have applicationSettings :
<applicationSettings>
<ABCdll.Properties.Settings>
<setting name="ABCConnectionString" serializeAs="String">
<value>ABCConnectionString</value>
</setting>
</ABCdll.Properties.Settings>
</applicationSettings>
When I deploy the application, will it automatically copy this
<applicationSettings> from my dll project app.config to the mainproject's
app.config ? If not, how shall I approach this issue ?

Thanks for your reply.

regards,
Andrew

RE: app.config file by MortenWennevik

MortenWennevik
Wed Mar 12 02:16:01 CDT 2008

Hi Andrew,

I believe you need to manually add a section with these keys to your main
app.config file if you want them visible. You don't have to though, as the
dll will be compiled with the initial settings, but they won't be visible
unless you do.

--
Happy Coding!
Morten Wennevik [C# MVP]


"Andrew" wrote:

> Hi,
> I have a question about the app.config file. I am using EnterpriseLibrary
> v3.1.
>
> 1) From what I read on this forum, I can only have 1 app.config file in my
> windows application. One of my dll projects have applicationSettings :
> <applicationSettings>
> <ABCdll.Properties.Settings>
> <setting name="ABCConnectionString" serializeAs="String">
> <value>ABCConnectionString</value>
> </setting>
> </ABCdll.Properties.Settings>
> </applicationSettings>
> When I deploy the application, will it automatically copy this
> <applicationSettings> from my dll project app.config to the mainproject's
> app.config ? If not, how shall I approach this issue ?
>
> Thanks for your reply.
>
> regards,
> Andrew
>

RE: app.config file by Andrew

Andrew
Wed Mar 12 07:48:01 CDT 2008

Thanks for your reply.
But in that case, then I cannot in the future make any changes to the
applicationSettings values.

Q: I know that my dll project can access the appSettings in the main
app.config file thru the code:
using System.Configuration;
string str = ConfigurationManager.AppSettings["abc"].ToString();

What is the code for doing this using ApplicationSettings instead of
AppSettings ? The configurationManager does not have the
"ApplicationSettings" property.
eg.
string str = (string)Properties.Settings.Default["aaa"];
I can use tis to access the <applicationSettings> in it's own app.config file.

Thanks.

regards,
Andrew

"Morten Wennevik [C# MVP]" wrote:

> Hi Andrew,
>
> I believe you need to manually add a section with these keys to your main
> app.config file if you want them visible. You don't have to though, as the
> dll will be compiled with the initial settings, but they won't be visible
> unless you do.
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>
>
> "Andrew" wrote:
>
> > Hi,
> > I have a question about the app.config file. I am using EnterpriseLibrary
> > v3.1.
> >
> > 1) From what I read on this forum, I can only have 1 app.config file in my
> > windows application. One of my dll projects have applicationSettings :
> > <applicationSettings>
> > <ABCdll.Properties.Settings>
> > <setting name="ABCConnectionString" serializeAs="String">
> > <value>ABCConnectionString</value>
> > </setting>
> > </ABCdll.Properties.Settings>
> > </applicationSettings>
> > When I deploy the application, will it automatically copy this
> > <applicationSettings> from my dll project app.config to the mainproject's
> > app.config ? If not, how shall I approach this issue ?
> >
> > Thanks for your reply.
> >
> > regards,
> > Andrew
> >

RE: app.config file by MortenWennevik

MortenWennevik
Wed Mar 12 09:10:02 CDT 2008

"Andrew" wrote:

> Thanks for your reply.
> But in that case, then I cannot in the future make any changes to the
> applicationSettings values.
>

You can. Just add the necessary lines in app.config when you need to. You
don't have to do it before the app is deployed either. Any changes in the
library regarding these keys need to be changed in the main app.config file
if necessary.

> Q: I know that my dll project can access the appSettings in the main
> app.config file thru the code:
> using System.Configuration;
> string str = ConfigurationManager.AppSettings["abc"].ToString();
>
> What is the code for doing this using ApplicationSettings instead of
> AppSettings ? The configurationManager does not have the
> "ApplicationSettings" property.
> eg.
> string str = (string)Properties.Settings.Default["aaa"];
> I can use tis to access the <applicationSettings> in it's own app.config file.
>
> Thanks.
>
> regards,
> Andrew
>

Use a Settings file in your library if you haven't already. Then simply
access the key using

string str = Settings.Default.aaa

which is type safe as well, so you could do Color myColor =
Settings.Default.SomeColor

Changes in the library Settings file will update the library app.config
file. If you specify application scope for the settings key you will get an
applicationSettings section in your app.config (user scope will create a
userSettings section)

The Settings file is basically a wrapper around app.config which makes it
much easier to code against a config file.
--
Happy Coding!
Morten Wennevik [C# MVP]



RE: app.config file by Andrew

Andrew
Wed Mar 12 10:56:01 CDT 2008

Thanks for your reply.

I understand the 1st part of your answer.

Let me clarify the 2nd part of my question. After I install my application
and deploy it, only one projectname.exe.config will be produced (which
belongs to my windows service).
In my code in one of my dll projects, how do I access the
applicationSettings in that config file ?

Do I use the System.Configuration.ConfigurationManager ... ??

Thanks

regards,
Andrew

"Morten Wennevik [C# MVP]" wrote:

> "Andrew" wrote:
>
> > Thanks for your reply.
> > But in that case, then I cannot in the future make any changes to the
> > applicationSettings values.
> >
>
> You can. Just add the necessary lines in app.config when you need to. You
> don't have to do it before the app is deployed either. Any changes in the
> library regarding these keys need to be changed in the main app.config file
> if necessary.
>
> > Q: I know that my dll project can access the appSettings in the main
> > app.config file thru the code:
> > using System.Configuration;
> > string str = ConfigurationManager.AppSettings["abc"].ToString();
> >
> > What is the code for doing this using ApplicationSettings instead of
> > AppSettings ? The configurationManager does not have the
> > "ApplicationSettings" property.
> > eg.
> > string str = (string)Properties.Settings.Default["aaa"];
> > I can use tis to access the <applicationSettings> in it's own app.config file.
> >
> > Thanks.
> >
> > regards,
> > Andrew
> >
>
> Use a Settings file in your library if you haven't already. Then simply
> access the key using
>
> string str = Settings.Default.aaa
>
> which is type safe as well, so you could do Color myColor =
> Settings.Default.SomeColor
>
> Changes in the library Settings file will update the library app.config
> file. If you specify application scope for the settings key you will get an
> applicationSettings section in your app.config (user scope will create a
> userSettings section)
>
> The Settings file is basically a wrapper around app.config which makes it
> much easier to code against a config file.
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>
>

RE: app.config file by MortenWennevik

MortenWennevik
Thu Mar 13 04:38:02 CDT 2008


"Andrew" wrote:

> Thanks for your reply.
>
> I understand the 1st part of your answer.
>
> Let me clarify the 2nd part of my question. After I install my application
> and deploy it, only one projectname.exe.config will be produced (which
> belongs to my windows service).
> In my code in one of my dll projects, how do I access the
> applicationSettings in that config file ?
>
> Do I use the System.Configuration.ConfigurationManager ... ??
>
> Thanks
>
> regards,
> Andrew
>

Same way you would access the settings in your dll.config

string str = Settings.Default.MyKey

If a match is found in the deployed .exe.config for that key that value is
used instead of the default compiled value in the dll. If no match is found,
the default compiled value is used.

If you insist on using appSettings read the value using
OpenExeConfiguration/OpenMappedExeConfiguration

Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection section = config.AppSettings;
string str = section.Settings["MyKey"].Value;


--
Happy Coding!
Morten Wennevik [C# MVP]




RE: app.config file by Andrew

Andrew
Thu Mar 13 11:57:02 CDT 2008

Thanks, I will try this out.

"Morten Wennevik [C# MVP]" wrote:

>
> "Andrew" wrote:
>
> > Thanks for your reply.
> >
> > I understand the 1st part of your answer.
> >
> > Let me clarify the 2nd part of my question. After I install my application
> > and deploy it, only one projectname.exe.config will be produced (which
> > belongs to my windows service).
> > In my code in one of my dll projects, how do I access the
> > applicationSettings in that config file ?
> >
> > Do I use the System.Configuration.ConfigurationManager ... ??
> >
> > Thanks
> >
> > regards,
> > Andrew
> >
>
> Same way you would access the settings in your dll.config
>
> string str = Settings.Default.MyKey
>
> If a match is found in the deployed .exe.config for that key that value is
> used instead of the default compiled value in the dll. If no match is found,
> the default compiled value is used.
>
> If you insist on using appSettings read the value using
> OpenExeConfiguration/OpenMappedExeConfiguration
>
> Configuration config =
> ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
> AppSettingsSection section = config.AppSettings;
> string str = section.Settings["MyKey"].Value;
>
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>
>
>