472,804 Members | 723 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 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 9508
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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.