Best way for Saving User Preferences?

T

Tom

I am planning on adding a Preferences form to my application and using the
Property Grid to display the preferences to the user. What do you think
would be the best way to save these preferences out to an XML file? Use the
CAB (Configuration Application Block)? Save the preferences in a class
object and serialize them out the the XML file? Write them out directly to
the XML file? Other ways???

Just want to get some thoughts together... want a way that is easy and
flexible (i.e. can add/remove preferences later on without a lot of hassle
or making the user ditch all their preferences and start over).

Thoughts?

Tom
 
T

Tom

Terry: Your answer leaves me with even more questions. For instance, I
already use the CMAB in my application to read a 'base' settings file that I
use to supply control settings. These settings come from a server file and
are NOT changed by the user - only myself. As I see it, the CMAB cannot read
anything but the MyApp.exe.config file (i.e. I would want the actual user
preferences settings stored in another XML file such as AppSettings.xml -
and the CMAB cannot be told to 'read' this file instead).

Also, even if I did use the CMAB, are you saying that the best way would be
to manually populate the CMAB? Remember, I am going to use a Property Grid
to interface the settings to the user. Would not simply serializing the
class that I 'bind' to the Property Grid suffice? Or are there bigger issues
to this?

Don't get the wrong idea - I am open to using the CMAB. I just don't see any
way for it to read anything but the base config file, and since I use that
file to supply hard-coded info to my users, I can't use it to store user
preferences. Again, not trying to answer my own question, but just curious
of the various ways I could do this (and what would be the most logical).
Thanks.

Tom
 
J

Jeremy

Tom said:
I am planning on adding a Preferences form to my application and using the
Property Grid to display the preferences to the user. What do you think
would be the best way to save these preferences out to an XML file? Use
the
CAB (Configuration Application Block)? Save the preferences in a class
object and serialize them out the the XML file? Write them out directly to
the XML file? Other ways???

Tom,

There are several good ideas in this MSDN Mag. article:
http://msdn.microsoft.com/msdnmag/issues/04/07/CustomPreferences/default.aspx

It discusses using isolated storage, registery, etc... I personally like
using XML because it's so much more portable and expandable than other
storage (INI, IS or Registry). Also, I usually use the XML Serializer and
create objects to represent the settings. But that's just my preference.

Whatever you do, the key points to keep in mind are storage, run-time
representation, and presentation to the user (in conjunction with how the
settings are stored).

Jeremy
 
O

One Handed Man \( OHM - Terry Burns \)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

Tom said:
Terry: Your answer leaves me with even more questions. For instance, I
already use the CMAB in my application to read a 'base' settings file that I
use to supply control settings. These settings come from a server file and
are NOT changed by the user - only myself. As I see it, the CMAB cannot read
anything but the MyApp.exe.config file (i.e. I would want the actual user
preferences settings stored in another XML file such as AppSettings.xml -
and the CMAB cannot be told to 'read' this file instead).

Also, even if I did use the CMAB, are you saying that the best way would be
to manually populate the CMAB? Remember, I am going to use a Property Grid
to interface the settings to the user. Would not simply serializing the
class that I 'bind' to the Property Grid suffice? Or are there bigger issues
to this?
What types of data can I store?
The Configuration Management Application Block provides support for storing
application configuration data contained in Hashtable objects as well as any
data type supported by the XmlSerializer class. In addition, the extensible
architecture of the Configuration Management Application Block means that
you can easily add support for any data structure with minimal development
effort.

HTH
 
G

Greg Burns

I haven't used CMAB much, but I quickly discovered it does NOT handle user
preferences out of the box. In other words, it does not store the xml file
to a user's profile folder. It can be modified to do so, but so much for
plug n play.

just my .02
Greg
 
O

One Handed Man \( OHM - Terry Burns \)

I think you will find that will most applications blocks they are a bit
'Full' of code and posibility, but sometimes can be a bit over the top. If
the OP just wants simple unsecure storage then a serialized output will do.
Isolated storage is another option but truly is a bit weird to work wotk.
Other than that there is allways the registry, or an SQL ( or like )
database storage as a possibility.



--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
R

Rockford Lhotka

Here's one possibility

http://msdn.microsoft.com/vbasic/us...library/en-us/dnadvnet/html/vbnet07082003.asp

Another is to use the CMAB. In that case, it is best to create a custom
XmlFileStorage provider that does token replacement for %ApplicationData% in
the "path" value - replacing it with
System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData).
You'll also need to alter it to create an empty file if one doesn't exist.
These changes are made in the Init method of the class.

Rocky
 
O

One Handed Man \( OHM - Terry Burns \)

I did suggest this but it was frowned upon.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
T

Tom

All: Just wanted to say THANKS for all the messages and help. I decided to
go with saving the preferences directly serialized to an XML file. I have a
separate class object that contains all my preferences settings; then I
'simply' serialize/deserialize that when needed. Works out great....

Thanks again for all your suggestions!

Tom
 
G

Guest

This sounds like the way I want to go. I can probably modify the
XmlFileStorage provider as you describe, but thought I'd ask if you have some
code snippets where you've already done this. I'd prefer not to reinvent the
wheel. Of course, I already am indebted to you for the suggestion on how to
accomplish this feature, so Thanks Already!
 

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