New setting at runtime

E

e-mre

Is it possible to add a new record to the settings file at run-time? Or is
the only possible time to add a new setting is design-time?

There are many many thing in my application that the user can customize for
him/her. I am thinking of stroring these in the settings file on the user PC
but I don't want to open a new record in the settings file for each
customizable setting.
If the setting is not in the settings file then use the default. If the user
changes from the default then add a new record to the settings file and save
the non-default value to the settings file.

e-mre
 
P

Peter Duniho

Is it possible to add a new record to the settings file at run-time? Or
is the only possible time to add a new setting is design-time?

Depends on what you mean. The settings you add in the designer are added
as properties to the Settings class. Obviously you can't do that at
run-time.
There are many many thing in my application that the user can customize
for him/her. I am thinking of stroring these in the settings file on the
user PC but I don't want to open a new record in the settings file for
each customizable setting.

IMHO, this is not a very useful feature. Your settings file should not be
very large, no matter how many settings you put into it. Further, if it's
a problem for the file to be large enough to contain all possible
settings, then that's a problem for the user who does change all possible
settings. I doubt you're in that situation, but if you are, you need to
reconsider your use of the settings storage.

And of course, if you're not, then it's not a good use of your time to try
to figure out how to avoid writing out settings that are not changed from
the default.

All that said, if you still decide you really want to do this, you should
be able to use the built-in XML-writing support to essentially implement
your own Settings class that does what you want. I think you could
probably override the Save() method in the Settings class (it's defined as
"partial" so you could add new code in a different .cs file), enumerating
the properties yourself and saving only those that differ from the
default. But since I haven't tried that, I don't really know how hard
that would be and what sort of pitfalls await you.

Pete
 
J

Jeffrey Tan[MSFT]

Hi E-mre ,

Have you reviewed Peter's reply to you? Does it make sense to you? If you
still need any help or have any concern, please feel free to feedback,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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