Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Application Settings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Slaughter - 15 Nov 2006 15:08 GMT
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
gbgeek - 15 Nov 2006 16:12 GMT
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

On Nov 15, 10:08 am, "Jon Slaughter" <Jon_Slaugh...@Hotmail.com>
wrote:
> 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
[quoted text clipped - 24 lines]
> Thanks,
> Jon
Ciaran O''Donnell - 15 Nov 2006 16:31 GMT
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

> Hi Jon,
>
[quoted text clipped - 62 lines]
> > Thanks,
> > Jon
Jon Slaughter - 15 Nov 2006 17:45 GMT
>I wrote an app that needed to save settings such as colors, fonts, etc...
>after hours of trying to use ConfigurationManager and AppSettings along
[quoted text clipped - 21 lines]
> "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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.