473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Modify value in app.config

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

System.Configur ation.Configura tion config =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);

string key = "Path";
string value = "New value";
config.AppSetti ngs.Settings.Ad d(key, value);
config.Save(Con figurationSaveM ode.Modified);
ConfigurationMa nager.RefreshSe ction("appSetti ngs");
It doesn't write the file. Could you tell me how to do it?
Thank you
May 30 '06 #1
5 9445
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.Configur ation.Configura tion config =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);

string key = "Path";
string value = "New value";
config.AppSetti ngs.Settings.Ad d(key, value);
config.Save(Con figurationSaveM ode.Modified);
ConfigurationMa nager.RefreshSe ction("appSetti ngs");


--
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.Spe cialFolder.Appl icationData

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******** ********@TK2MSF TNGP05.phx.gbl. ..
I need to modify a value in the app.config file with this code:

System.Configur ation.Configura tion config =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);

string key = "Path";
string value = "New value";
config.AppSetti ngs.Settings.Ad d(key, value);
config.Save(Con figurationSaveM ode.Modified);
ConfigurationMa nager.RefreshSe ction("appSetti ngs");
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.Spe cialFolder.Appl icationData


Is it the same as Application.Use rAppDataPath?
May 30 '06 #4
Looking at Roeder's Reflector, it is identical for standard apps - however,
for ClickOnce (NetworkDeploye d) apps it looks at
CurrentDomain.G etData("DataDir ectory"); 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.Connecti onStrings.Conne ctionStrings["DBConnecti on"].IsReadOnly

returns false so that is writable.

"Marc Gravell" <ma**********@g mail.comwrote in message
news:eJ******** ******@TK2MSFTN GP04.phx.gbl...
Looking at Roeder's Reflector, it is identical for standard apps -
however, for ClickOnce (NetworkDeploye d) apps it looks at
CurrentDomain.G etData("DataDir ectory"); 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
10930
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 value type object:
2
1251
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
13388
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
5938
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 do in my form ?? Please give some adivce.
1
2125
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
1824
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. allow roles="Administrator"), I will also need to modify the values there. TIA, JP
1
2784
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, which will result in saving it. Saving files during the build process is dangerous and can result in incorrect build outputs in future. Do you want to continue with the check out?
1
3243
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
2976
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 = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath) ' Find app setting to change
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.