473,405 Members | 2,287 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,405 software developers and data experts.

Modify value in app.config

I need to modify a value in the app.config file with this code:

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

string key = "Path";
string value = "New value";
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings") ;
It doesn't write the file. Could you tell me how to do it?
Thank you
May 30 '06 #1
5 9430
This config is readonly.
But you can use System.Xml namespace to write smth in it
I need to modify a value in the app.config file with this code:

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

string key = "Path";
string value = "New value";
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings") ;


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

May 30 '06 #2
Hi,

You cannot, it;s readonly. I had a link somewhere explaining the reasons
behind this. One is that the changes in it will affect all the users of the
app, not the particular user that did it.

If you need to store changing values you can use the registry or even better
create your own config file and store it in the user ApplicationData folder
: Environment.SpecialFolder.ApplicationData

See opennetcf.org library for a good implementation of a config like class.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Alberto" <al*****@nospam.es> wrote in message
news:OW****************@TK2MSFTNGP05.phx.gbl...
I need to modify a value in the app.config file with this code:

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

string key = "Path";
string value = "New value";
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings") ;
It doesn't write the file. Could you tell me how to do it?
Thank you

May 30 '06 #3
Ignacio Machin ( .NET/ C# MVP ) wrote:

If you need to store changing values you can use the registry or even better
create your own config file and store it in the user ApplicationData folder
: Environment.SpecialFolder.ApplicationData


Is it the same as Application.UserAppDataPath?
May 30 '06 #4
Looking at Roeder's Reflector, it is identical for standard apps - however,
for ClickOnce (NetworkDeployed) apps it looks at
CurrentDomain.GetData("DataDirectory"); I'm not 100% where this value comes
from, however! (it isn't one of the special cases in Locate(), so something
must be providing it explicitly - presumably "fusion" / ClickOnce).

Marc
May 30 '06 #5
I have the same situation, I have tested the IsReadOnly properties

config.ConnectionStrings.ConnectionStrings["DBConnection"].IsReadOnly

returns false so that is writable.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:eJ**************@TK2MSFTNGP04.phx.gbl...
Looking at Roeder's Reflector, it is identical for standard apps -
however, for ClickOnce (NetworkDeployed) apps it looks at
CurrentDomain.GetData("DataDirectory"); I'm not 100% where this value
comes from, however! (it isn't one of the special cases in Locate(), so
something must be providing it explicitly - presumably "fusion" /
ClickOnce).

Marc

Aug 25 '06 #6

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

Similar topics

2
by: KalleD | last post by:
Given: ArrayList al=new ArrayList(); int i=1; al.Add(i); How can I change the value of al to 2? (without removing the object and then adding a new one) This won't work, since int is an...
2
by: Tayo | last post by:
I can't make changes to my web.config files. Even if I try using notepad, the system says that the file in held by another process. Please hel Tayo
3
by: Maileen | last post by:
Hi, I've asked yesterday if someone already modify data into XML file using VB.NET. In fact, my XML file is like that. .... <DB> <DB_Loc>
4
by: Agnes | last post by:
I my login form, I want to let the user choose which database (there are A,B,C three databases ) I know I can use App.config to change the SQL server (database name). However, I don't know how to...
1
by: alberto | last post by:
Please, I need a example about how to modify the app.config with the class ConfigurationManager. Thank you very much.
1
by: Joey | last post by:
Is this possible? I have an app where we are using forms authentication and are allow editing/changing of security role names. Since I have set permissions with <locationtags in web.config (i.e....
1
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I have an asp.net solution with a web deployment project. When we try to build/debug, we get the message: An editor or project is attempting to check out a file that is modified in memory,...
1
by: =?Utf-8?B?TGV2ZW50IERhZ2lzdGFubGk=?= | last post by:
I think you are running your code from VS. Just run the exe from outside and it will work. Thanks, Levent Dagistanli "Andrew" wrote:
4
by: pasam | last post by:
Hi I am creating installer for asp.net i am using this code for to modify web.config file but i cant whats wrong this code ' Get configuration. Dim config As Configuration =...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.