Hello,
I was wondering if anyone knew if it was possible to make changes to
an application's App.config file at runtime and then be able to access
those changes immediately.
The following is an example of what I'm trying to achieve:
I tried a test by creating a simple app Test.exe that has some basic
settings made available to it in the runtime file Test.exe.config .
E.g.
<appSettings>
<add key="setting" value="123" />
</appSettings>
I then started the app, and printed out the setting through a call to
ConfigurationSe ttings.AppSetti ngs["setting"] with result:
setting = 123
Then, while the app was still running, I changed the value of the
setting as such, and saved the file Test.exe.config :
<appSettings>
<add key="setting" value="abc" />
</appSettings>
Again I printed the out the setting through the call to
ConfigurationSe ttings.AppSetti ngs["setting"] but there was no change,
the output was still
setting = 123
whereas I would expect it to be
setting = abc
It seems that the contents of the App.config file are loaded into some
cache upon startup, and any physical changes to the file itself go
unnoticed until the application is instantiated again.
Is this the case? If so, any ideas on how to go about achieving what I
am trying to do. I figure the only option would be to create a custom
configuration class that reads from some custom config file when
requested.
Hope to hear from someone,
Danny 3 7076
Hi,
Probabily you can use the FileSystemWatch er to create notifications when
there are changes to this file.
HTH,
APG
Danny wrote: Hello,
I was wondering if anyone knew if it was possible to make changes to an application's App.config file at runtime and then be able to access those changes immediately.
The following is an example of what I'm trying to achieve:
I tried a test by creating a simple app Test.exe that has some basic settings made available to it in the runtime file Test.exe.config . E.g.
<appSettings> <add key="setting" value="123" /> </appSettings>
I then started the app, and printed out the setting through a call to ConfigurationSe ttings.AppSetti ngs["setting"] with result:
setting = 123
Then, while the app was still running, I changed the value of the setting as such, and saved the file Test.exe.config :
<appSettings> <add key="setting" value="abc" /> </appSettings>
Again I printed the out the setting through the call to ConfigurationSe ttings.AppSetti ngs["setting"] but there was no change, the output was still
setting = 123
whereas I would expect it to be
setting = abc
It seems that the contents of the App.config file are loaded into some cache upon startup, and any physical changes to the file itself go unnoticed until the application is instantiated again.
Is this the case? If so, any ideas on how to go about achieving what I am trying to do. I figure the only option would be to create a custom configuration class that reads from some custom config file when requested.
Hope to hear from someone,
Danny
Danny,
Check this article: "Applicatio n Configuration Files Explained" at http://msdn.microsoft.com/library/de...et04222003.asp.
Alek
"Danny" <da**********@d efence.gov.au> wrote in message
news:db******** *************** ***@posting.goo gle.com... Hello,
I was wondering if anyone knew if it was possible to make changes to an application's App.config file at runtime and then be able to access those changes immediately.
The following is an example of what I'm trying to achieve:
I tried a test by creating a simple app Test.exe that has some basic settings made available to it in the runtime file Test.exe.config . E.g.
<appSettings> <add key="setting" value="123" /> </appSettings>
I then started the app, and printed out the setting through a call to ConfigurationSe ttings.AppSetti ngs["setting"] with result:
setting = 123
Then, while the app was still running, I changed the value of the setting as such, and saved the file Test.exe.config :
<appSettings> <add key="setting" value="abc" /> </appSettings>
Again I printed the out the setting through the call to ConfigurationSe ttings.AppSetti ngs["setting"] but there was no change, the output was still
setting = 123
whereas I would expect it to be
setting = abc
It seems that the contents of the App.config file are loaded into some cache upon startup, and any physical changes to the file itself go unnoticed until the application is instantiated again.
Is this the case? If so, any ideas on how to go about achieving what I am trying to do. I figure the only option would be to create a custom configuration class that reads from some custom config file when requested.
Hope to hear from someone,
Danny
>I was wondering if anyone knew if it was possible to make changes to an application's App.config file at runtime and then be able to access those changes immediately.
Not without a lot of code of your own, for two main reasons:
1) The .NET configuration system will read its settings at app startup
only, and not ever after that - so any changes you may have made will
never be reflected in the ConfigurationSe ttings object
2) The .NET config system does not offer any way to manipulate an
existing .config file out of the box. And this is by design - under
normal circumstances, your app's .config file will reside in the app's
directory, where regular users should *not* have any write permissions
in the first place - so you wouldn't be able to modify that file
anyway.
Instead, for user settings, I'd recommend using some kind of a
XML-based config file, and store it e.g. using the IsolatedStorage
classes, to ensure the user can actually write back changes to his
settings!
Also, there are a ton of free third-party configuration classes and
components - just go search www.codeproject.com for "configurat ion
..NET" or something like that - you'll find quite a few links.
Marc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Programmer |
last post by:
Hi everyone
Well here is my problem
I hope you can help me
|
by: Mathew |
last post by:
Hi
How do you specfiy the version of the .net runtime libraries loaded for a
..net controls hosted in Internet Explorer 6? I have a control that's
designed to work with .NET 1.1, but after installing the VS.NET 2005 beta
the web browser embedded control is now running in the .NET 2.0 beta runtime
environment, and crashing.
Is it possible to have different IE hosted controls running side by side in
different versions of the .NET...
|
by: Marina Anufreichik |
last post by:
Hi,
After deploymnet web application on web server I can access page on local
machine and login fine but when I'm trying to access web site from remote
machine I can see login page, but when I'm trying to login with correct
credentials it give me error:
Server Error in '/PDVMgr' Application.
----------------------------------------------------------------------------
|
by: Ajay Pal Singh |
last post by:
Hi,
I am creating a web service, which needs to take some actions based on the
config file. I need a way to listen the changes as they occur in the config
file so that the service can take appropriate action for the cahnges. Is
there any way i can implement this.
Thanks,
Ajay
|
by: kl |
last post by:
Hello
My aspx pages run fine with non-secure server. When I tried to run them with https://, on the browser side, the runtime error occurred with suggestions of adding the following configuration
<configuration><system.web><customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/></sytem.web></configuration
and on the server side, the errors were
access denied to "C:\WebFiles\web.config". Failed to start monitoring file...
| |
by: Iwan Petrow |
last post by:
Hi,
I have dynamic properties (for checkboxes Checked property which I use
in Option dialog box) . After I change checkboxes check properties I
use DOM to save the changed values in the config files (it works fine -
it changes the values). But if I reopen the option dialog (I create
new one and call ShowDialog) the values are the same at the beginning
(as if the config file hasn't been changed). Also if I restart the
application I have...
|
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 a web application and if
I need to read the connection string it is reading the connection string from
the web.config of web application. I am not knowing how to change the
Application domain so that it reads the App.config file instead of...
|
by: Alison Givens |
last post by:
....... that nobody knows the answer.
I can't imagine that I am the only one that uses parameters in CR.
So, my question again:
I have the following problem.
(VB.NET 2003 with CR)
I have a report with a multiple-value discrete value and a rangevalue.
The report shows fine in the viewer, but when I hit the export to pdf
|
by: robin9876 |
last post by:
In Microsoft Knowledgebase article 821268 (http://
support.microsoft.com/?id=821268 ) there are some configuration
settings for .net v1.1
Are these the same in v2 or are their additional options?
For an application which has a .Net v2 windows form application on
client pc's and connects to .Net v2 web services. Which level (web
server of client) would these changes need to be made at and in what
config file?
|
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...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |