Hi all
I've been trying without sucess to write values back to my app.coonfig. I have put my config and code below as I am having zero luck but I have followed MSDN/google pages.

Does anyone know where I am going wrong?
thanks

config.AppSettings.Settings["FTPHost"].Value = tbFtpHost.Text;
            config.AppSettings.Settings["FTPUserName"].Value = tbFtpUsername.Text;
            config.AppSettings.Settings["FTPUserPasswd"].Value = tbFtpUserpasswd.Text;
            config.AppSettings.Settings["FTPRemoteDir"].Value = tbFtpRemoteDir.Text;

            config.AppSettings.Settings.Remove("FTPHost");
            config.AppSettings.Settings.Add("FTPHost", tbFtpHost.Text);

            config.AppSettings.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="FTPHost" value="host.domain.com"/>
    <add key="FTPUserName" value="username"/>
    <add key="FTPUserPasswd" value="password"/>
    <add key="FTPRemoteDir" value="/u1/EDI_DROP"/>
  </appSettings>
</configuration>

Twice I have received "token expired" error trying to reply to this... I am really peeved! Anyway, run the program outside the debugger and check the debug\application.exe.config file for the changes. I would explain further, but I've already wasted a 1/2 hour trying too...

EDIT: I'll try to elaborate briefly and hope I don't get another "token expired"...

When you build your app, it will create the application.exe.config file. When you run in the debugger, it will update the application.vshost.exe.config file. When you make changes in the debug mode, it will update the vshost file, but not the other. However, when you run outside the debugger it will update the application.exe.config file...

commented: you da man +1

Oh my god! I spent flippin ages trying to work that out!!!!!!!! never thought to try outside VS. Jeez, you live and learn... Many thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.