Home All Groups Group Topic Archive Search About

Dynamically load user.config

Author
2 Jun 2006 10:34 AM
lee atkinson
Hi - is it possible to load a user.config file?

What I would like to do is to be able to load a user.config file and
then set the current properties to the properties within that file.
This would then allow the user to download their own user settings.

I could of course parse the XML and do it that way, but I thought there
may be a better and easier way.

Thanks

Author
3 Jun 2006 6:56 AM
Aaron Feng
Show quote
"lee atkinson" wrote:

> Hi - is it possible to load a user.config file?
>
> What I would like to do is to be able to load a user.config file and
> then set the current properties to the properties within that file.
> This would then allow the user to download their own user settings.
>
> I could of course parse the XML and do it that way, but I thought there
> may be a better and easier way.
>
> Thanks
>
>

Not sure if this is what you want, but in your app.config or web.config you
can reference an user.config file like this:

<appSettings file="user.config">
  <add key="ConnectionString" Value="..."  />
</aapSetting>

In your user.config

<appSettings>
    <add key="ConnectionString Value="something else" /?
</appSettings>

Cheers,

Aaron
http://aaronfeng.blogspot.com/
Author
7 Jun 2006 4:05 PM
lee atkinson
Hi Aaron

I should have made it clear it was .NET 2.0

What I did was to copy over the user.config, then call
Settings.Reload()

Lee
Author
8 Jun 2006 10:10 PM
Aaron Feng
"lee atkinson" wrote:

> Hi Aaron
>
> I should have made it clear it was .NET 2.0
>
> What I did was to copy over the user.config, then call
> Settings.Reload()
>
> Lee
>
>

For example, if you have a user.config and app.config both files have the
ConnectionString property when you do:

ConfigurationManager.AppSettings["ConnectionString"];

It will return the value that is stored in the user.config not app.config. 
Assuming you set it up like I showed you before, and make sure you copy the
user.config when you finish compiling (set this in Visual Studio).  Sometimes
you might need to "touch" the app.config for it to pickup the user.config.

This will allow people who have user.config setup use a different
configuration.

Cheers,

Aaron
http://aaronfeng.blogspot.com
Author
19 Jun 2006 10:52 PM
lee atkinson
Hi Aaron - as I said, I'm using .NET 2.0.

Although your solution is valid in version 2.0, it's more apt for
version 1.0.

I'm actually talking about the user.config files that are supported and
managed by .NET 2.0.

My solution worked fine anyhow.

Lee

AddThis Social Bookmark Button