473,385 Members | 1,908 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,385 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 9538
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.