Application Settings

J

Jon Slaughter

I wrote an app that needed to save settings such as colors, fonts, etc...
after hours of trying to use ConfigurationManager and AppSettings along with
a few other things I finally found that I could just use
global::properties.xxx.Settings.Default.yyy

where xxx is the namespace and yyy is a setting created in the settings
dialog.

This is an extremly easy way to save and restore properties but I'm
wondering how general it is and if its a good idea to use it?

Also, where are these settings stored? It seems that its somewhere in the
CLR(maybe not the appropriate term) cache or something? The only way I
could reset the settings is by setting them to some default values and then
saving them.

One issue I was having was when I was using AppSettings[key]. I could never
find any settings even though I had both application and user defined
settings created in app.config. Are these settings suppose to be the same
as the ones above or are they different? (such as a different section/group
name in the xml config file?)

e.g., if I created a user or application defined setting called
"SomeSetting" in the settings page and then tried to reference it by
AppSettings["SomeSetting"], I would also get a null string.


Thanks,
Jon
 
G

gbgeek

Hi Jon,

I can't give you as much help as others on here but I can tell you how
I use the settings.

In my solution explorer, there is a Properties folder beneath the
project. Expanding that out allows me to see the Resources and the
Settings. When I have something that I want to persist, I double click
on the Settings item and it brings up an editor to allow me to enter
the variables and their scope (application or user). Once I have my
variables set up, I go back to my code where I want to use them.

At the top, I put the following using statement:

using myNamespace.Properties;

That keeps me from having to type so much when I want to use them.
Then, in my code, I use

Settings.Default.MySetting

I do this for keeping track of the window size and position and some
colors. Mostly settings that the user will change. To get them to
persist between application uses, you must make the change to the
setting and then do a Settings.Default.Save. I usually do this in the
Closing event of my primary form.

I'm not exactly sure where they are saved. I've not had many problems
out of them and haven't investigated that. I did a quick search in the
documenation and didn't see anything obvious. I ran FileMon and watched
as a small app came up and then went down. It appears that there are
some files being opened and closed in my accounts Local Settings folder
as well as the Application Data folder.

HTH some
 
G

Guest

The User Settings in .NET2 are saved in a folder in Application Data folder
for the user and the Application settings are saved in a settings file with
the app.
The AppSettings[string] is for reading the old <appSettings> element from
the config which is now completly defunct and marked obsolete I believe.

HTH

Ciaran O'Donnell

gbgeek said:
Hi Jon,

I can't give you as much help as others on here but I can tell you how
I use the settings.

In my solution explorer, there is a Properties folder beneath the
project. Expanding that out allows me to see the Resources and the
Settings. When I have something that I want to persist, I double click
on the Settings item and it brings up an editor to allow me to enter
the variables and their scope (application or user). Once I have my
variables set up, I go back to my code where I want to use them.

At the top, I put the following using statement:

using myNamespace.Properties;

That keeps me from having to type so much when I want to use them.
Then, in my code, I use

Settings.Default.MySetting

I do this for keeping track of the window size and position and some
colors. Mostly settings that the user will change. To get them to
persist between application uses, you must make the change to the
setting and then do a Settings.Default.Save. I usually do this in the
Closing event of my primary form.

I'm not exactly sure where they are saved. I've not had many problems
out of them and haven't investigated that. I did a quick search in the
documenation and didn't see anything obvious. I ran FileMon and watched
as a small app came up and then went down. It appears that there are
some files being opened and closed in my accounts Local Settings folder
as well as the Application Data folder.

HTH some

I wrote an app that needed to save settings such as colors, fonts, etc...
after hours of trying to use ConfigurationManager and AppSettings along with
a few other things I finally found that I could just use
global::properties.xxx.Settings.Default.yyy

where xxx is the namespace and yyy is a setting created in the settings
dialog.

This is an extremly easy way to save and restore properties but I'm
wondering how general it is and if its a good idea to use it?

Also, where are these settings stored? It seems that its somewhere in the
CLR(maybe not the appropriate term) cache or something? The only way I
could reset the settings is by setting them to some default values and then
saving them.

One issue I was having was when I was using AppSettings[key]. I could never
find any settings even though I had both application and user defined
settings created in app.config. Are these settings suppose to be the same
as the ones above or are they different? (such as a different section/group
name in the xml config file?)

e.g., if I created a user or application defined setting called
"SomeSetting" in the settings page and then tried to reference it by
AppSettings["SomeSetting"], I would also get a null string.

Thanks,
Jon
 
J

Jon Slaughter

Jon Slaughter said:
I wrote an app that needed to save settings such as colors, fonts, etc...
after hours of trying to use ConfigurationManager and AppSettings along
with a few other things I finally found that I could just use
global::properties.xxx.Settings.Default.yyy

where xxx is the namespace and yyy is a setting created in the settings
dialog.

This is an extremly easy way to save and restore properties but I'm
wondering how general it is and if its a good idea to use it?

Also, where are these settings stored? It seems that its somewhere in the
CLR(maybe not the appropriate term) cache or something? The only way I
could reset the settings is by setting them to some default values and
then saving them.

One issue I was having was when I was using AppSettings[key]. I could
never find any settings even though I had both application and user
defined settings created in app.config. Are these settings suppose to be
the same as the ones above or are they different? (such as a different
section/group name in the xml config file?)

e.g., if I created a user or application defined setting called
"SomeSetting" in the settings page and then tried to reference it by
AppSettings["SomeSetting"], I would also get a null string.

Ok, thanks guys. One more thing though. It seems one can be more general(or
maybe I mean specific) in defining settings and create sections and groups
using some methods in configurationmanager? I'm just curious about this as
I might need it later. What I have found off the net doesn't give much
explination of how it works and the msdn is pretty bad at explaining the
details.

As far as I can tell is that the configuration data is stored in XML files
and one can create "nodes" and data using some methods that abstract the XML
details. Is this about right?

Thanks again,
Jon
 

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

Top