473,508 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing value to config file

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.AppSett ings.Set("LidbsdPath",
g_strLidbsdPath)

I am getting an error message saying "Collection is read-only"? How can I
fix this
Nov 22 '05 #1
4 2940
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.

"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
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.AppSett ings.Set("LidbsdPath",
g_strLidbsdPath)

I am getting an error message saying "Collection is read-only"? How can I
fix this

Nov 22 '05 #2
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.

"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
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.AppSett ings.Set("LidbsdPath",
g_strLidbsdPath)

I am getting an error message saying "Collection is read-only"? How can I
fix this

Nov 22 '05 #3
> 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.AppSett ings.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.Spec ialFolder.CommonApplicatio
nData;

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

m_LocalUserConfig.ConfigurationType=Environment.Sp ecialFolder.LocalApplicati
onData;

I hope this helps?

--
http://www.skyscan.be
Nov 22 '05 #4
> 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.AppSett ings.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.Spec ialFolder.CommonApplicatio
nData;

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

m_LocalUserConfig.ConfigurationType=Environment.Sp ecialFolder.LocalApplicati
onData;

I hope this helps?

--
http://www.skyscan.be
Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3772
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
2
319
by: Job Lot | last post by:
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 ...
5
3213
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
2
12686
by: MK | last post by:
Is there any way to write into the app config at runtime? I want to store position, height and width of my forms.
19
2513
by: Noozer | last post by:
I need to keep my application settings in a file that users can copy/backup/etc. Before I start using the old INI file standard, is there any easy way to use XML files to hold application...
1
1127
by: chauc3r | last post by:
I'm having problems writing to a text file. Basically it refuses to write anything. The file is created. At the appropiate times it goes into the correct if statements (I have verified this...
0
1066
by: Rum | last post by:
Hi, I`m writing an application that can be updated from remote server. Application config file is updating too (adding new sections etc...) When application is updating i make a copy of old config...
6
2887
by: Peted | last post by:
Hi, im wanting to store some custom text strings in the app.config file of a c# app, to be retreived and updated when the app runs. using c# 2005 express in my testing i am using the code...
0
1145
parshupooja
by: parshupooja | last post by:
Hey All, I have old vb.net application and I have various users for that.where I have XML file as datasource. Till now for each user application was installed seperately. only difference...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.