0

I have created a windows form application which taking values from App config file. I wanted to make it, when after the build, I goes to the app config file and open it and change the value. Then program is taking that value. But sadly it isn't working . Can you tell me where I was wrong?

int EmId = Properties.Settings.Default.UserId; //taking the UserId value from Appconfig
bl_Static.empIDFixed = EmId; // assign it to the Static variable

this is the Appconfig code that I'm changing the "value"

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /></startup>

<userSettings>
    <PopUpPAS.Properties.Settings>
        <setting name="UserId" serializeAs="String">
            <value>4</value> 
        </setting>
    </PopUpPAS.Properties.Settings>
</userSettings>

<runtime>

When I do that change Externally ( Opening the app config file from note pad and change the value to another value) . It doesn't get the value.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • *But sadly it isn't working* it's working but obviously it saves `userSettings` in [different file](https://stackoverflow.com/questions/1075204/when-using-a-settings-settings-file-in-net-where-is-the-config-actually-stored) (also you have to call Save()) ... also we have 2020: if you install app into PF you cannot write there as normal user ... – Selvin Jul 29 '20 at 09:11
  • Did you try an approach like this https://stackoverflow.com/questions/5468342/how-to-modify-my-app-exe-config-keys-at-runtime – HugoHiasl Jul 29 '20 at 09:16

1 Answers1

0

After my test, I found that your code has no problems. I suggest you follow my steps to create a project.

My Settings.settings is as follows: Settings.settings

My code:

private void Form1_Load(object sender, EventArgs e)
     {
         int EmId = Properties.Settings.Default.UserId;
         MessageBox.Show(EmId.ToString());
     }

The execution process: Execution process

dear_vv
  • 2,350
  • 1
  • 4
  • 13