By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,770 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,770 IT Pros & Developers. It's quick & easy.

Dynamic settings entries with Application Settings.

P: n/a
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.

Feb 1 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" wrote:
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.

Feb 1 '07 #2

P: n/a
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?

On Feb 1, 10:12 am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
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" wrote:
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.

Feb 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.