Saving user settings in winforms C#

P

parez

Whats the best way of storing user settings and application settings
in a winforms application?

Should i create my own xml files and save it in
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
?

What about the Settings class.? There were examples in vb.net which
lets a user save.

If it is readonly then why is there a save method?
 
J

Jon Skeet [C# MVP]

Whats the best way of storing user settings and application settings
in a winforms application?

The .NET 2.0 settings classes are pretty good for many uses.
Should i create my own xml files and save it in
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
?

I wouldn't if I were you.
What about the Settings class.? There were examples in vb.net which
lets a user save.

If it is readonly then why is there a save method?

Calling Save() is fine - but it will only save the user settings, not
application settings.

The previously saved settings will be loaded by default next time
they're accessed, assuming you use the auto-generated class
(Settings.settings etc in Visual Studio).

Jon
 
P

parez

The .NET 2.0 settings classes are pretty good for many uses.


I wouldn't if I were you.



Calling Save() is fine - but it will only save the user settings, not
application settings.

The previously saved settings will be loaded by default next time
they're accessed, assuming you use the auto-generated class
(Settings.settings etc in Visual Studio).

Jon

Yes I am using the Settings.settings file

So if dont write my own xml files how will i save application
settings?
 
J

Jon Skeet [C# MVP]

Yes I am using the Settings.settings file

So if dont write my own xml files how will i save application
settings?

Do they *have* to be application settings rather than user settings? I
don't know offhand of any easy way of saving application settings,
although there may well be a way somewhere.
 
A

Andy

Yes I am using the Settings.settings file

So if dont write my own xml files how will i save application
settings?

Application settings aren't meant to be changed out in the wild. It's
more of a way for you to store settings instead of hard coding
values.
 
P

parez

Application settings aren't meant to be changed out in the wild. It's
more of a way for you to store settings instead of hard coding
values.

Thats what i thought.. I have used web.config in asp.net applications
for storing read only appplication configuration stuff..

So I will either have to write my custom xml or save to DB???
 
J

Jon Skeet [C# MVP]

Thats what i thought.. I have used web.config in asp.net applications
for storing read only appplication configuration stuff..

So I will either have to write my custom xml or save to DB???

Well, the settings mechanism is reasonably extensible - you may find
there's already code you can take.

However, you should ask yourself what distinction you want to draw
between user and application settings beyond the fact that one set is
writable and the other isn't. What harm would it do to make all the
settings user settings?
 
A

Andy

Thats what i thought.. I have used web.config in asp.net applications
for storing read only appplication configuration stuff..

So I will either have to write my custom xml or save to DB???

I think you misunderstand... Settings can be either Application (which
aren't meant to be changed) or User (which can be saved as described
in this thread). If you want the user to be able to change settings,
either diretly or indirectly, you should set them as user settings.
 
P

parez

Well, the settings mechanism is reasonably extensible - you may find
there's already code you can take.

However, you should ask yourself what distinction you want to draw
between user and application settings beyond the fact that one set is
writable and the other isn't. What harm would it do to make all the
settings user settings?

yea.. i can think in that direction.. thansk..
 

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