Use of app.config and saving user preferences... 
Author Message
 Use of app.config and saving user preferences...

I have a question on the best way to use the app.config file.  I know that I
can use this to pass configuration data to a main assembly, but that it can
also be used to 'store' user preferences, such as last user id, last window
size and location, etc.

However, what if I have both static -and- user preference data that I want
to store?  Let's say, for instance, that I have data in an app.config that
is static and that I (as the programmer) may want to change and deploy with
the application (for example, database id, database configuration string,
etc etc).  So I may change this data in the XML config file and deploy it
with every update of my application (say, once every month). But if the
application were also to store user preference data (such as last screen
size and location) in the app.config file, it would get overwritten every
time I redeployed the application and the user preferences would be lost.

As in VB6, I could put this user preference data into the registry, but from
what I see that is not the .NET way of doing things.  So where should user
preference data/settings be stored so they won't get overwritten during a
redeployment of the application (and redeployment of the app.config file)?
Should there be two config files? I.E. one app.config and maybe a
user.config?  Or what?

Just curious as to how others are doing this and what is the appropriate
.NET way.... Thanks in advance.

Tom



Sun, 18 Sep 2005 22:29:47 GMT  
 Use of app.config and saving user preferences...

Quote:
> I have a question on the best way to use the app.config file.  I know that
I
> can use this to pass configuration data to a main assembly, but that it
can
> also be used to 'store' user preferences, such as last user id, last
window
> size and location, etc.

In a winforms app, user-specific settings still belong in the registry under
HKEY_CURRENT_USER\Software...

David



Sun, 18 Sep 2005 22:49:53 GMT  
 Use of app.config and saving user preferences...
Hi Tom, <g>

You can still access the registry using managed code by looking at the
Registry class. It contains everything you need to access the registry.

--
==============================================
Happy to Help,
Tom Spink

http://dotnetx.betasafe.com > .NET code

One Day,

Quote:
> I have a question on the best way to use the app.config file.  I know that
I
> can use this to pass configuration data to a main assembly, but that it
can
> also be used to 'store' user preferences, such as last user id, last
window
> size and location, etc.

> However, what if I have both static -and- user preference data that I want
> to store?  Let's say, for instance, that I have data in an app.config that
> is static and that I (as the programmer) may want to change and deploy
with
> the application (for example, database id, database configuration string,
> etc etc).  So I may change this data in the XML config file and deploy it
> with every update of my application (say, once every month). But if the
> application were also to store user preference data (such as last screen
> size and location) in the app.config file, it would get overwritten every
> time I redeployed the application and the user preferences would be lost.

> As in VB6, I could put this user preference data into the registry, but
from
> what I see that is not the .NET way of doing things.  So where should user
> preference data/settings be stored so they won't get overwritten during a
> redeployment of the application (and redeployment of the app.config file)?
> Should there be two config files? I.E. one app.config and maybe a
> user.config?  Or what?

> Just curious as to how others are doing this and what is the appropriate
> .NET way.... Thanks in advance.

> Tom



Sun, 18 Sep 2005 23:12:48 GMT  
 Use of app.config and saving user preferences...
Hello Tom,


Quote:
> I have a question on the best way to use the app.config file.  I know
that I
> can use this to pass configuration data to a main assembly, but that
it can
> also be used to 'store' user preferences, such as last user id, last
window
> size and location, etc.

Do not save simple program settings to configuration files.

http://www.palmbytes.de/content/dotnet/optionslib.htm

Regards,
Herfried K. Wagner



Mon, 19 Sep 2005 02:49:13 GMT  
 Use of app.config and saving user preferences...
Quote:
> Hello Tom,


>> I have a question on the best way to use the app.config file.  I know
> that I
>> can use this to pass configuration data to a main assembly, but that
> it can
>> also be used to 'store' user preferences, such as last user id, last
> window
>> size and location, etc.

> Do not save simple program settings to configuration files.

> http://www.palmbytes.de/content/dotnet/optionslib.htm

> Regards,
> Herfried K. Wagner

Nice code.  I particularly like that it was done using SharpDevelop.

However, I disagree with you.  The settings really should be in the
appSettings section of the application .config file.  Unfortunately,
Microsoft chose not to supply us with methods to WRITE to the application
.config file in the .NET Framework.  Fortunatately, it's just an XML file,
so it's not too hard.  As a matter of fact, this Optionslib could be
converted quite easily to be able to handle writing to the application
.config file.

However, since I don't have time to do that at the moment, I recommend the
sample code from Chapter 15 of Dino Esposito's book, "Applied XML
Programming for .NET" where he tackles this very issue.

The sample code is available for download for free from:

http://www.microsoft.com/mspress/books/6235.asp

                                -chris

--
Chris J. Breisch, MCSD.NET, MCDBA



Mon, 19 Sep 2005 03:45:13 GMT  
 Use of app.config and saving user preferences...
Actually, Chris, I agree with you - it would seem to be better to put the
settings there.  If you go to
http://www.devx.com/dotnet/Article/11616/1954?pf=true there is an article
there that describes an AppSettingsManager class that does exactly this.

However, this still doesn't address the problem of having SOME of the
settings to be static and some to be dynamic.  Remember, I am going to have
some settings in there that I may change on a build by build basis; in other
words, if I change something in that file i build 1.0.1, and then copy that
updated XML build to each users workstation, then it will overwrite the old
one with their configuration settings in it. That is why I was thinking of
using an app.config and maybe a user.config XML files.

Any other thoughts?

Tom



Quote:
> > Hello Tom,


> >> I have a question on the best way to use the app.config file.  I know
> > that I
> >> can use this to pass configuration data to a main assembly, but that
> > it can
> >> also be used to 'store' user preferences, such as last user id, last
> > window
> >> size and location, etc.

> > Do not save simple program settings to configuration files.

> > http://www.palmbytes.de/content/dotnet/optionslib.htm

> > Regards,
> > Herfried K. Wagner

> Nice code.  I particularly like that it was done using SharpDevelop.

> However, I disagree with you.  The settings really should be in the
> appSettings section of the application .config file.  Unfortunately,
> Microsoft chose not to supply us with methods to WRITE to the application
> .config file in the .NET Framework.  Fortunatately, it's just an XML file,
> so it's not too hard.  As a matter of fact, this Optionslib could be
> converted quite easily to be able to handle writing to the application
> .config file.

> However, since I don't have time to do that at the moment, I recommend the
> sample code from Chapter 15 of Dino Esposito's book, "Applied XML
> Programming for .NET" where he tackles this very issue.

> The sample code is available for download for free from:

> http://www.microsoft.com/mspress/books/6235.asp

> -chris

> --
> Chris J. Breisch, MCSD.NET, MCDBA



Mon, 19 Sep 2005 05:05:17 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Advice on saving array of users preferences

2. Saving user preferences

3. Save Settings to App.config

4. saving and using config info

5. setting connection using key in app.config

6. Saving Preferences

7. Saving Preferences in .INI

8. User Preferences located in a seperate file

9. User Preferences

10. managing user preferences...opinions needed

11. Default User Preferences

12. Saving user info in the app.path

 

 
Powered by phpBB® Forum Software