Dynamic settings entries with Application Settings.

S

Sin Jeong-hun

I've read the "How to: Create Application Settings" article (http://
msdn2.microsoft.com/en-us/library/ms171565.aspx) on the MSDN. It
looked fine. But this code is only good when all the settings entries
are defined at the compile time. And I have to modify the class itself
each and everytime I need more entries. So, is it impossible to get/
save dynamic entries?

I mean, instead of,
MyUserSettings.Background=color;
color=MyUserSettings.Background;

use this
MySettings["key"]=color;
color=MySettings["key"];
where "key" can be any string. If "key" doesn't exist, then a new
entry for "key" is created.

I could create my own class from scratch, but I just wonder if I could
utilize the already exsiting ApplicatoinSettingsBase class. Thank you.
 
G

Guest

You could certainly do this since the configuration file is well-formed XML.
The problem is that when you have modified and resaved this file, your
application will not automatically reload it unless it is restarted. If it is
an ASP.NET web app, and you modify the web.config (same concept) this will
cause the application to restart, and you will lose all session, cache and
application state.

Does that help?
Peter
 
S

Sin Jeong-hun

First of all, thank you for your reply.
You could certainly do this since the configuration file is well-formed XML.
But, what do you mean by this? Does this mean that 1)I can do create
my own settings class from scratch or 2)I can derive a class that does
that from the ApplicationSettingsBase?

I tried
this["undefined key"]=value;
but it causes an exception. How can I dynamically add the "undefined
key" at run-time?

You could certainly do this since the configuration file is well-formed XML.
The problem is that when you have modified and resaved this file, your
application will not automatically reload it unless it is restarted. If it is
an ASP.NET web app, and you modify the web.config (same concept) this will
cause the application to restart, and you will lose all session, cache and
application state.

Does that help?
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

Sin Jeong-hun said:
I've read the "How to: Create Application Settings" article (http://
msdn2.microsoft.com/en-us/library/ms171565.aspx) on the MSDN. It
looked fine. But this code is only good when all the settings entries
are defined at the compile time. And I have to modify the class itself
each and everytime I need more entries. So, is it impossible to get/
save dynamic entries?
I mean, instead of,
MyUserSettings.Background=color;
color=MyUserSettings.Background;
use this
MySettings["key"]=color;
color=MySettings["key"];
where "key" can be any string. If "key" doesn't exist, then a new
entry for "key" is created.
I could create my own class from scratch, but I just wonder if I could
utilize the already exsiting ApplicatoinSettingsBase class. Thank you.
 

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