Writing value to config file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write value for a key in <appSettings><add key="LidbsdPath"
value="" /></appSettings> section of config file from vb.net app, using
statement below

System.Configuration.ConfigurationSettings.AppSettings.Set("LidbsdPath",
g_strLidbsdPath)

I am getting an error message saying "Collection is read-only"? How can I
fix this
 
You cannot that way. You would need to load the config file into an
XmlDocument object and make the change, then save it.

The config file will not be reloaded until the app is reloaded.
 
I am trying to write value for a key in said:
value="" /></appSettings> section of config file from vb.net app, using
statement below

System.Configuration.ConfigurationSettings.AppSettings.Set("LidbsdPath",
g_strLidbsdPath)

I am getting an error message saying "Collection is read-only"? How can I
fix this
This config file is for start-up only so you can add start-up configuation
like serial number or prdefined settings without having to recompile the
project...

Unless you are a power user, or administrator user, modern applications that
are installed inder "C:\Program Files" normally have read-only acces. And
the same is true for Internet based executables and applications run form
CD-ROM. Meaning you normall should not be able to write to any file located
in the C:\Program Files" folder. And that happens to be the location of that
config file.
So the question is now, where do I write the configurations?
The registration database could do the trick but even better is at these 3
new locations Microsoft is pushing:
All happen to be in the "My documents" folders....

If you need to save the configuration on one computer, then go to another
and load it from there then you use:

m_RoamingUserConfig.ConfigurationType=Environment.SpecialFolder.ApplicationD
ata;

If you need the configuration the same for any user logged on that same
machine but independend of another machine then use:

m_AllUserConfig.ConfigurationType=Environment.SpecialFolder.CommonApplicatio
nData;

And finally, and probably most needed, for user independend configuration
location:

m_LocalUserConfig.ConfigurationType=Environment.SpecialFolder.LocalApplicati
onData;

I hope this helps?
 
Back
Top