Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Saving user settings in winforms C#

1 view
Skip to first unread message

parez

unread,
Mar 11, 2008, 12:05:46 PM3/11/08
to
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?


Jon Skeet [C# MVP]

unread,
Mar 11, 2008, 12:07:30 PM3/11/08
to
On Mar 11, 4:05 pm, parez <psaw...@gmail.com> wrote:
> 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

parez

unread,
Mar 11, 2008, 1:47:40 PM3/11/08
to

Yes I am using the Settings.settings file

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

Andy

unread,
Mar 11, 2008, 2:06:40 PM3/11/08
to

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.

Jon Skeet [C# MVP]

unread,
Mar 11, 2008, 2:06:06 PM3/11/08
to
parez <psa...@gmail.com> wrote:

<snip>

> 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.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

parez

unread,
Mar 11, 2008, 3:32:13 PM3/11/08
to

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???

Jon Skeet [C# MVP]

unread,
Mar 11, 2008, 3:46:58 PM3/11/08
to
parez <psa...@gmail.com> wrote:

<snip>

> > 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???

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?

Andy

unread,
Mar 11, 2008, 4:02:35 PM3/11/08
to

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.

parez

unread,
Mar 11, 2008, 4:03:17 PM3/11/08
to
On Mar 11, 3:46 pm, Jon Skeet [C# MVP] <sk...@pobox.com> wrote:

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

Joel Lucsy

unread,
Mar 12, 2008, 10:32:45 AM3/12/08
to
Jon Skeet [C# MVP] wrote:
> On Mar 11, 4:05 pm, parez <psaw...@gmail.com> wrote:
>> Should i create my own xml files and save it in
>> Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
>> ?
>
> I wouldn't if I were you.
>

I'm curious as to why you wouldn't recommend this?

--
Joel Lucsy
"The dinosaurs became extinct because they didn't have a space program."
-- Larry Niven

Jon Skeet [C# MVP]

unread,
Mar 12, 2008, 10:44:52 AM3/12/08
to
Joel Lucsy <jjl...@gmail.com> wrote:
> Jon Skeet [C# MVP] wrote:
> > On Mar 11, 4:05 pm, parez <psaw...@gmail.com> wrote:
> >> Should i create my own xml files and save it in
> >> Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
> >> ?
> >
> > I wouldn't if I were you.
>
> I'm curious as to why you wouldn't recommend this?

Because using the built-in classes is so much easier.

Jani

unread,
May 11, 2008, 6:19:00 AM5/11/08
to
Hi parez,

I agree with Jon, for this case are user settings the best solution.
The article http://www.codeproject.com/KB/dotnet/user_settings.aspx
describes the pros.

Jani

0 new messages