Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:15:31+00:00 2026-06-16T03:15:31+00:00

It works fine with Read , but I can’t seem to get the Write

  • 0

It works fine with Read, but I can’t seem to get the Write happening. It doesn’t throw any IO Exception when I try to write file. As if nothing happened.

Here is my code, please look at the GetValue() and SetValue() functions:

using System.Configuration;

public class AppConfig {
    private string _username;
    private string _password; 

    public AppConfig() {
        _filePath = GetValue("Username");
        _password = GetValue("Password");
        //... more
    }
    public string Password {
        get { return _password; }
        set { SetValue("Password", value); _password = value; }
    }
    public string Username {
        get { return _username; }
        set { SetValue("Username", value); _username = value; }
    }
    private void SetValue(string key, string val) {
        var cfg= ConfigurationManager
                .OpenExeConfiguration(ConfigurationUserLevel.None);
        cfg.AppSettings.Settings[key].Value = val;
        cfg.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");
    }
    private string GetValue(string key) {
        return ConfigurationManager.AppSettings[key];
    }
}

And this is the app.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>

    <add key ="Password" value ="123456"/>
    <add key ="Username" value ="hohoho"/>

  </appSettings>
</configuration>

Any idea how to make the Write happening? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:15:32+00:00Added an answer on June 16, 2026 at 3:15 am

    The configuration system in .Net was not designed to let you programmatically save changes to the app.config in the assembly folder. I know there is a “Save” method there, but those changes actually save to a copy of the config file. The location of the copy depends on the scope of the setting.

    Application Settings such as these:

    <appSettings>
         <add key="" value=""/>
    </appSettings>
    

    Have “application scope” if I recall correctly. If you use the Settings page in the project settings page or open Settings.settings in the Properties folder, you can choose the scope (User or Application).

    This way, changes to the settings are persisted for the current user or for that specific version of the application. These copies are stored in a generated folder somewhere in the %APPDATA% for the appropriate account. The configuration system automatically loads the settings again depending on who’s logged in.

    This is why you also have an “Upgrade” method. It allows you to add settings to new versions of your application and upgrade the user’s settings, causing only the new properties to be added to the user’s copy. In this way, the setting in the app.config in the assembly folder is only the default value for the setting.

    The comments above touch on why this is the way it works: Files inside Program Files are intended to remain untouched after installation and UAC ensures this.

    I suggest reading up on the configuration system, it is quite powerful. If you still really want to modify app.config, you have to write custom code to modify the app.config file directly and

    • install into user’s profile folders, or
    • always run your program as
      an administrator
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read lots of questions on this general topic on SO but can't seem
Typically I use cat filename|while read line; do echo $line This works fine...but I
I've read some posts on this, but still can't get the answer to my
I'm writing a coprocess program using pipe. It works fine when the child read
I am using json to read records. It works perfectly fine if I use
works fine on the desktop with xampp but when i upload it to my
Git works fine on my dev box, but ever so often, I'll go to
it works fine on 64 bit machines but for some reason will not work
This works fine: GET /mvc/Movies/TitleIncludes/Lara%20Croft When I submit a request that contains a colon,
This may be really obvious, but in rails how can I get the contents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.