App.Config文件帮助 [英] App.Config file help

查看:99
本文介绍了App.Config文件帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的项目中有一个App.Config文件,看起来是这样的:

Hi guys I have a App.Config file in my project that looks so :

<configuration>
    <appsettings>
      <add key="DatabasePath" value="Database=C:\Users\Roelof\Documents\Visual Studio 2008\Projects\ClientServices <br mode=" hold=" />        \Database Information\Database\\CLIENTSERVICES.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=localhost" />
      <add key="RegisteredHDD" value="No" />
      <add key="Activationcode" value="" />
    </appsettings>
</configuration>




我的问题是在运行时我更改了字段.它会更改,但不会显示在文件中.谁能帮忙!




The problem that I have is that at Runtime i change the fields. It changes but doesnt show in the file. Can anyone please help!

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    config.AppSettings.Settings["RegisteredHDD"].Value = "Yes";
                    config.AppSettings.Settings["Activationcode"].Value = final;
                    config.AppSettings.Settings.Add("LastDateFeesChecked", DateTime.Now.ToShortDateString());

                    config.Save(ConfigurationSaveMode.Modified);

推荐答案

当您说它没有显示在文件中时,您确定在看正确的文件?我最近回答了另一个关于app.config到底是什么引起的困惑的问题.在您的项目中,您将看到app.config,但是如果您在构建文件夹中查看,则不会看到此文件.为什么会这样?

好吧,app.config是一个占位符配置文件,它被重命名以匹配您的应用程序可执行文件.假设您的exe文件名为MyApplication.exe,则应用程序读取的配置文件为MyApplication.exe.config.

检查该文件中是否有更改,而不是app.config(并在重新编译应用程序之前执行该操作,您不希望仅由于构建而覆盖更改).
When you say that it doesn''t show in the file, are you sure that you are looking at the right file? I''ve recently answered another question caused by confusion as to what app.config really is. In your project, you''ll see app.config, yet if you look in the build folders you won''t see this file. Why is that?

Well, app.config is a placeholder configuration file which gets renamed to match your application executable. Suppose your exe is called MyApplication.exe, the config file that is read by the application is MyApplication.exe.config.

Check that file for your changes rather than app.config (and do it before you recompile the application, you don''t want to overwrite your changes just because of a build).


这篇关于App.Config文件帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆