473,549 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with app.config

I have a app.config file and I'd like to read and modify strings in it.

I can read but I can't modify strings. The code I'm using is this:

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

string key = "myKey";
config.Save(Con figurationSaveM ode.Modified);

Configuration.M anager.RefreshS ection("appSett ings");

What's my mistake? Thank you very much
Feb 26 '07 #1
5 7651
Alberto,

I am not sure if this is a bug in .NET, but we have found that we cannot
write to the app.config file either. We have found a work around though.

In your main App.Config you would point to another config that you are
allowed to make changes to.

Example: (App.Config)
<configuratio n>
<appSettings file="NewApp.co nfig"></appSettings>
</configuration>

Example: (NewApp.Config)
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
Put all of your app settings in here
</appSettings>
------

Now if you make changes to NewApp.Config you have to close and restart the
application in order for the new settings to take effect.

Hope this helps. If anyone has a better solution to this please let me
know.

Sincerely,
Shannon

"Alberto" <ańsk********@a sdf.eswrote in news:O$6P4$YWHH A.4796
@TK2MSFTNGP05.p hx.gbl:
I have a app.config file and I'd like to read and modify strings in it.

I can read but I can't modify strings. The code I'm using is this:

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

string key = "myKey";
config.Save(Con figurationSaveM ode.Modified);

Configuration.M anager.RefreshS ection("appSett ings");

What's my mistake? Thank you very much
Feb 26 '07 #2
From the documentation:

If the configuration file has changed since this Configuration object was
created, a run-time error occurs.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Alberto" <ańsk********@a sdf.eswrote in message
news:O$******** ******@TK2MSFTN GP05.phx.gbl...
>I have a app.config file and I'd like to read and modify strings in it.

I can read but I can't modify strings. The code I'm using is this:

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

string key = "myKey";
config.Save(Con figurationSaveM ode.Modified);

Configuration.M anager.RefreshS ection("appSett ings");

What's my mistake? Thank you very much

Feb 26 '07 #3
so, it can't be changed???

"Kevin Spencer" <un**********@n othinks.comescr ibió en el mensaje
news:uP******** *****@TK2MSFTNG P06.phx.gbl...
From the documentation:

If the configuration file has changed since this Configuration object was
created, a run-time error occurs.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Alberto" <ańsk********@a sdf.eswrote in message
news:O$******** ******@TK2MSFTN GP05.phx.gbl...
>>I have a app.config file and I'd like to read and modify strings in it.

I can read but I can't modify strings. The code I'm using is this:

System.Configu ration.Configur ation config =
ConfigurationM anager.OpenExeC onfiguration(Co nfigurationUser Level.None);

string key = "myKey";
config.Save(Co nfigurationSave Mode.Modified);

Configuration. Manager.Refresh Section("appSet tings");

What's my mistake? Thank you very much


Feb 26 '07 #4
It can be changed, but not by the same instance of the Configuration object.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Alberto" <al*****@nospam .eswrote in message
news:up******** ******@TK2MSFTN GP05.phx.gbl...
so, it can't be changed???

"Kevin Spencer" <un**********@n othinks.comescr ibió en el mensaje
news:uP******** *****@TK2MSFTNG P06.phx.gbl...
>From the documentation:

If the configuration file has changed since this Configuration object was
created, a run-time error occurs.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Alberto" <ańsk********@a sdf.eswrote in message
news:O$******* *******@TK2MSFT NGP05.phx.gbl.. .
>>>I have a app.config file and I'd like to read and modify strings in it.

I can read but I can't modify strings. The code I'm using is this:

System.Config uration.Configu ration config =
Configuration Manager.OpenExe Configuration(C onfigurationUse rLevel.None);

string key = "myKey";
config.Save(C onfigurationSav eMode.Modified) ;

Configuration .Manager.Refres hSection("appSe ttings");

What's my mistake? Thank you very much



Feb 26 '07 #5
Sorry but I don't understand the way I should do this. Do you meant that
after read the current app.config with a Configuration object, I should
create another Configuration object to write the changes?
Thank you

"Kevin Spencer" <un**********@n othinks.comescr ibió en el mensaje
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
It can be changed, but not by the same instance of the Configuration
object.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Alberto" <al*****@nospam .eswrote in message
news:up******** ******@TK2MSFTN GP05.phx.gbl...
>so, it can't be changed???

"Kevin Spencer" <un**********@n othinks.comescr ibió en el mensaje
news:uP******* ******@TK2MSFTN GP06.phx.gbl...
>>From the documentation:

If the configuration file has changed since this Configuration object
was created, a run-time error occurs.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

I had the same problem once. Fixed it using the same solution.

"Alberto" <ańsk********@a sdf.eswrote in message
news:O$****** ********@TK2MSF TNGP05.phx.gbl. ..
I have a app.config file and I'd like to read and modify strings in it.

I can read but I can't modify strings. The code I'm using is this:

System.Confi guration.Config uration config =
Configuratio nManager.OpenEx eConfiguration( ConfigurationUs erLevel.None);

string key = "myKey";
config.Save( ConfigurationSa veMode.Modified );

Configuratio n.Manager.Refre shSection("appS ettings");

What's my mistake? Thank you very much



Feb 27 '07 #6

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

Similar topics

5
3572
by: Jeff Johnson | last post by:
I'm using forms authentication to protect a subfolder within my site. I've got it working fine except for two issues: (1) When I do a RedirectFromLogin page I have to put a cookie path ("/" works, or "/mysubdir") or else the auth cookie doesn't get set. I'd like to know why this is necessary. (2) When I call SignOut() the auth cookie is...
1
3965
by: harinathch | last post by:
Hi, Iam working with myapplication.exe.config file in my vb.net windows application.Its working fine in my development environment. When i test this application in some other machine using exe and all related dll's and files. Iam getting following error. Thx in advance. Hari.
7
4030
by: vamichael | last post by:
When I try to run the Website Administration Tool from my published application using http://localhost/myapp/webadmin.axd I am getting a "resource not found" error message. I can use the Admin tool from the IDE however. I noticed some people referring to a directory called c:\Inetpub\wwwroot\aspnet_webadmin\, which i do not have on my...
2
2129
by: tshad | last post by:
This has been driving me crazy. I have been trying to get the error handling working on my system and can get parts of it working and others won't work at all. I found that you can't access session variables from Application_Error event, but I need to so I don't need to set up traces to see what they are during an error. I am emailing...
5
2338
by: barry | last post by:
Below are my setting in the web.config file for forgotten passwords. I receive a completion that the password has been sent but upon looking in outlook there is no email sent to me. I have also tried 127.0.0.1 for the network host <system.net> <mailSettings> <smtp deliveryMethod="Network" from="mopliger@sbcglobal.net"> <network...
4
4452
by: =?Utf-8?B?SmFu?= | last post by:
I have a .NET 2.0 application divided in two assemblies; the exe and a dll. The application generates a plugin-dll which is then loaded in a separate AppDomain (along with a second instance of my application dll). It's been working for months and now the it's not working from my application exe anymore but still working from NUnit when...
8
2915
by: WT | last post by:
Hello, I am trying to update a configuration section for my web.config with SetRawXml withoutr result. I have given modfidy rigth to Network Services account which is running the ..NET2 pool in wich my application is running, here is my code: System.Configuration.Configuration config =...
1
1750
by: JJ | last post by:
I've a strange problem: My customErrors section in my web.config doesn't seem to be working on the live host. By that, I mean that when I type in an address of a page that doesn't exist, I get the standard 404 error page and not my custom one. It works fine on both my visual studio web server and my local IIS, with exaclty the same...
5
10486
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a machine running IIS 6.0. I just replaced the web.config and several aspx pages in the application and now the style sheets are not working. the images from the themes work but not the css files. Any help. -- Jerry
0
7484
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...
0
7997
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...
1
7515
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6091
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5124
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...
0
3510
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1974
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
1
1089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
798
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...

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.