Registry or equivalent in .NET ?

  • Thread starter Thread starter Anthony
  • Start date Start date
A

Anthony

Hi,

I've written a small C# application which has toolbars which can be
hidden and repositioned. How should I record the current state of the
toolbars when the program shuts down so that it can be displayed in the
same way next time its run ?

Previously under MFC I would have used the registry to save this
configuration info. Is this still the preferred method in .NET or is
there a better way. I have a vague idea you're supposed to use meta
data, but how would you do this in practice ?

Thanks,
Anthony.
 
I continue to use the Registry for UI element position / size / etc
settings.

I see config files as being much more stable than this: something that
is changed occasionally, and (almost?) never by the program itself.

Meta data is typically compiled into your program, and so is not an
appropriate place to save settings like this (I'm not even sure how
that would work). :-)
 
I'll throw out my $0.02, but wait for other responses. :) I've got an app
that I'm working on right now. It's gonna sit in the system tray, and have
a number of set-up options, as well as storing the current/last
configuration. I plan on storing the current status in an XML configuration
file. In my little mind, that's the way MS is pushing us. It went from an
INI file (in the Windows 3.x days) to the registry (Win9x), and now's it's
apparently heading back to INI type files. I don't know who makes these
things up, but apparently there's job security in architecting these things.
:)

I look forward to other input in this thread!

Clint
 
I like the app.config file model. For one thing, it doesn't add to the
System Registry, which may be able to handle a lot of data, but still can
have a tendancy to fill up, slow down, and end up with a lot of orphaned
data in it from uninstalls etc. Besides the capability of fairly easy and
direct editing of the configuration, which is a plus as far as I'm
concerned, the XML format makes it extensible, and it is only loaded when
the app is running, vs. the System Registry, which is fully loaded with all
sorts of data not being used at any given time.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
To my mind....

ini files = "expect that user should be able to tweek the apps settings
manualy". Ie modifing an ini file would not be considered something the
user should not do.

reg = "dont mess with me". Users touching the reg should know the
dangers of doing so and should not complain it there attemps to mess
with your setting result in the application not functioning properly.

Anyway Im very sure lots of people will disagree with me on this point.


So positioning toolbars and turning them on/off = "something a user
should not mess with outside of the mechanisim you app provides to do
so." = reg.

Also reg can be per-user .... This means that eveyr user on the
computer will have there own setting for the toolbars. This is also a
good reason to use the reg for this.


-dm
 
The .net answer to your question is to modify the config file.

A nice article on this topic is here:
http://odetocode.com/Articles/418.aspx



--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Also reg can be per-user .... This means that eveyr user on the
computer will have there own setting for the toolbars. This is also a
good reason to use the reg for this.

The .Net Platform 2.0 has per-user configuration built in.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
ini files = "expect that user should be able to tweek the apps settings
manualy". Ie modifing an ini file would not be considered something the
user should not do.

reg = "dont mess with me". Users touching the reg should know the
dangers of doing so and should not complain it there attemps to mess
with your setting result in the application not functioning properly.

Application configuration files can be encrypted.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
That's an awfully long row to hoe just to stop the user from messing
with your window positions and sizes. As well, there may be parts of
the app config that the user _should_ be able to tweak.

I prefer to dump transient stuff like UI settings in the Registry, and
leave app.config for application configuration parameters such as
(encrypted) database connection strings and locations on things on the
network. Stuff that changes rarely but should be tweakable by users or
by administrators. In addition, I don't have the application itself
writing the config file. The config file is version controlled and
rolled out to production, just like the application is.
 
Kevin said:
The .Net Platform 2.0 has per-user configuration built in.

Yes, thanks I found this after talking to a colleague. For the
information of others, here's how it works:

(1) You go to the solution properties and select the "Settings" tab.
You create settings for each property you want to store.

(2) You read the property's value in your program with a statement
like: Value = Properties.Setting.Defaults.MyProperty;

(3) You save updated settings using the statement:
Properties.Settings.Default.Save().

This will retain user settings between program runs. This works by
storing the settings in an XML file in the following location:

C:\Documents and Settings\UserName\Local Settings\Application
Data\AppName\...

Where UserName is the user currently logged in, and AppName is the name
of the program.

Anthony.
 
Yes, it's a very cool feature!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top