473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Changing data in App.config

I'm trying to use VB.NET's 2003 ConfigurationSettings.AppSettings.Set()
method of updating values but getting error "Collection is read-only".

How can I change values of keys in the App.config file programatically?

Here is my code:
Imports System.Configuration

Imports System.Collections.Specialized

Module Module1

Sub Main()

Dim sAttr As String

sAttr = ConfigurationSettings.AppSettings("Key0")

MessageBox.Show(sAttr)

ConfigurationSettings.AppSettings.Set("Key0", "11")

MessageBox.Show(sAttr)

End Sub

End Module

'***********************************************

'App Config File:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<add key="Key0" value="00"/>

</appSettings>

</configuration>

'********************************************

-Anatoly
Jul 22 '05 #1
2 9539
You cannot, well, unless you want to open the file into a DOM, update it,
then write it back out.

"Anatoly" <nospam.com> wrote in message
news:Ol**************@TK2MSFTNGP15.phx.gbl...
I'm trying to use VB.NET's 2003 ConfigurationSettings.AppSettings.Set()
method of updating values but getting error "Collection is read-only".

How can I change values of keys in the App.config file programatically?

Here is my code:
Imports System.Configuration

Imports System.Collections.Specialized

Module Module1

Sub Main()

Dim sAttr As String

sAttr = ConfigurationSettings.AppSettings("Key0")

MessageBox.Show(sAttr)

ConfigurationSettings.AppSettings.Set("Key0", "11")

MessageBox.Show(sAttr)

End Sub

End Module

'***********************************************

'App Config File:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<add key="Key0" value="00"/>

</appSettings>

</configuration>

'********************************************

-Anatoly

Jul 22 '05 #2
See this blog for full source code and REAL cautions.
http://ryanfarley.com/blog/archive/2004/07/13/879.aspx

Note, if your app will EVER be used by more than one person on the same
machine, then writing to the app config means they will share the config.
Your app also must have admin privs, since the app config lives in the
program files folder. On machines where the desktop environment is
centrally managed, an idea whose time has come, your app won't run.

Instead, consider saving any local configuration changes in the user's
Documents and Settings folder.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Anatoly" <nospam.com> wrote in message
news:Ol**************@TK2MSFTNGP15.phx.gbl...
I'm trying to use VB.NET's 2003 ConfigurationSettings.AppSettings.Set()
method of updating values but getting error "Collection is read-only".

How can I change values of keys in the App.config file programatically?

Here is my code:
Imports System.Configuration

Imports System.Collections.Specialized

Module Module1

Sub Main()

Dim sAttr As String

sAttr = ConfigurationSettings.AppSettings("Key0")

MessageBox.Show(sAttr)

ConfigurationSettings.AppSettings.Set("Key0", "11")

MessageBox.Show(sAttr)

End Sub

End Module

'***********************************************

'App Config File:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<add key="Key0" value="00"/>

</appSettings>

</configuration>

'********************************************

-Anatoly

Jul 22 '05 #3

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

Similar topics

0
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
2
by: Anatoly | last post by:
I'm trying to use VB.NET's 2003 ConfigurationSettings.AppSettings.Set() method of updating values but getting error "Collection is read-only". How can I change values of keys in the App.config...
5
by: Sridhar | last post by:
Hi, I have created a project which contains classes to read the data from the database. This project has an App.Config file which contains the SqlConnection String. when this code is called from...
1
by: Bala Nagarajan | last post by:
Hello, I am building a web service application in which i will have to implement logging based on user id. My question is where do i store the user ids? Since the nature of this problem is so...
0
by: VB Programmer | last post by:
ASP.NET 2.0 site... Using web deployment project. Allowed web.config to be updateable. Settings not only in web.config but also in appSettings.config and connectionStrings.config. Question:...
2
by: Siegfried Heintze | last post by:
I made the following change to my web.config file (see fragment below) but does not seem to affect the timeout on my web page. I have a huge session state but since I'm the only one using it, I'd...
5
by: John | last post by:
Hi I am trying to set a new password using the following code; Dim u As MembershipUser = Membership.GetUser(UserName) Dim OldPassword As String OldPassword = u.GetPassword If...
7
by: Larry Neylon | last post by:
Hi there, We are in the process of implementing Membership and Role Management and have a problem with the connection strings in our web.config. We currently have a system that on...
2
by: RB0135 | last post by:
Hi, I hope I worded the subject correctly. Under VS2005, I have created the wizard to add a datasource that connects to my SQL2005 server. I ran through the wizard and this created a Dataset,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
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,...

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.