Windows Forms application configuration

D

Dave Veeneman

Is there a 'best practice' methodology for storing and retrieving
configuration data in C# Windows Forms applications? I'm talking about the
sort of stuff that went into INI files in the old days.

I'm planning to create a class to hold initialization information, then
serialize the class to the application directory to persist it. Any better
way to get the job done? Thanks

Dave Veeneman
DNL Systems
 
W

William Ryan eMVP

Adding a .NET config file works pretty well although you can't write to it
from within your app. If you use the .configs then you can have designer
support for dynamic properties and it's very easy to access the values. I
believe MS recently put out a Configuration application block as well that
may be helpful.
 
J

JD

For now, you pretty much have to "roll your own". There are a number of
online articles, many of which suggest the same thing you're planning to do.
Check www.codeproject.com, as I recall seeing at least one there.

William's suggestion of .config for the app is fine if you're just reading
from the file at runtime. The framework doesn't have built-in support to
write/modify the file. There are articles/samples that show you how to do
that, but it's not terrribly safe -- if your app is in Program Files, a
standard "user" account won't have write/change privileges. You can use the
Environment type or Isolated Storage (either way) to store it in a
user-specific, permissions-safe location.

JD
 
J

Joerg Jooss

Dave said:
Is there a 'best practice' methodology for storing and retrieving
configuration data in C# Windows Forms applications? I'm talking
about the sort of stuff that went into INI files in the old days.

I'm planning to create a class to hold initialization information,
then serialize the class to the application directory to persist it.
Any better way to get the job done? Thanks

There's a nice article on MSDN describing several ways to store
configuration data.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/persistappsettnet.asp

Cheers,
 

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