c#


How do i reload app.config File data


i have a program that edits app.config file and save it. however i can edit and save but I can't reload the app.config data without restarting the app.
i tried couple of ways.i'm not sure what is wrong
this is my code..
private void btnSave_Click(object sender, EventArgs e)
{
UpdateConfig("IP",radtxtIP.Text, "myApp.exe");
UpdateConfig("port", radtxtPort.Text, "myApp.exe");
LoadConfigData();
}
private void UpdateConfig(string key, string value, string fileName)
{
var configFile = ConfigurationManager.OpenExeConfiguration(fileName);
configFile.AppSettings.Settings[key].Value = value;
configFile.Save();
}
public void LoadConfigData()
{
ConfigurationManager.RefreshSection("appSettings");
Properties.Settings.Default.Reload();
radtxtIP.Text = ConfigurationManager.AppSettings["IP"];
radtxtPort.Text = ConfigurationManager.AppSettings["port"];
}
when i click save button it gives me old settings.
i added this code after reading some questions in stackoverflow,but no use
ConfigurationManager.RefreshSection("appSettings");
Properties.Settings.Default.Reload();
do I need to make a new instance of ConfigurationManager?
is it ok the way i use Configuration data.?
my app uses app.config data in many places. so have to restart the app when I change my configuration data.
You might find this helpfull https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.refreshsection.aspx
Please make sure you load the new settings as shown below
// Get the AppSettings section.
AppSettingsSection appSettingSection = (AppSettingsSection)config.GetSection(sectionName);

Related Links

How can I dump data on the screen in c#
Send application sound to a specific audio device C#
Cancelling a task [duplicate]
How to customize error message of OAuthAuthorizationServerProvider?
c# Use dll with different versions in one directory
MySqlConnection Parameters cutting off data at 200bytes
error: 'object' no definition/extension method
Checking a condition every minute on a WebAPI application
Get paragraphs formatting by numbering
How to Update the department, manager properties in Userprincipal?
LINQ where int equals many results
Report download progress to user interface
Generic Object Method not working correctly
Remove from Grid View ASP.NET
AccessViolation when calling Marshal.Copy using user32 SendMessage
Cast to base class from derived class

Categories

HOME
postgresql
grizzly
sip
readdir
lithium
ms-access-2010
opacity
kohana
handlebars.js
scapy
rmarkdown
restheart
sahi
subprocess
vichuploaderbundle
osclass
jetbrains
mongodb-replica-set
web-worker
nsoperation
amazon-data-pipeline
gomobile
gnu-screen
prepros
policy
poisson
mongoose-im
marionette
scripting-language
meteor-accounts
recreate
exacttarget
tikz
visual-studio-debugging
matlab-compiler
leaderboard
motion
contenteditable
firefox-developer-edition
pexpect
taiga
scrapinghub
opos
enet
jenkins-docker
opticalflow
vertex-shader
copy-constructor
zsh-completion
universe
tinybox2
jcalendar
fadein
dday
bioconductor
android-filterable
p4python
playn
page-refresh
targetprocess
system.diagnostics
accpac
touch-typing
teamstudio-unplugged
javadb
information-hiding
illegalargumentexception
rpt
mvcgrid
visual-studio-setup-proje
winrun4j
pidgin
sqldatasource
dayofweek
grunt-wiredep
surfaceview
ardor3d
xcode5.1
scidb
spawn
generator-expression
nsregularexpression
invalidoperationexception
systrace
idtabs
joomla1.7
datejs
zend-validate
windows-xp-embedded
funambol
file-processing
quazip
html5-animation
linq-to-mysql
pkcs#7
software-update
stackless

Resources

Encrypt Message