[英]Reading values from App config file externally
I have created a windows form application which taking values from App config file.我创建了一个 windows 表单应用程序,它从 App 配置文件中获取值。 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"这是我正在更改“值”的 Appconfig 代码
<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.
它没有得到价值。
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我的 Settings.settings 如下: 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执行过程:执行过程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.