四联光电智能照明论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2100|回复: 0
打印 上一主题 下一主题

使用ConfigurationManager保存数据到App.config

[复制链接]
  • TA的每日心情
    开心
    2018-7-4 09:08
  • 97

    主题

    392

    帖子

    6095

    积分

    论坛元老

    Rank: 8Rank: 8

    积分
    6095
    跳转到指定楼层
    楼主
    发表于 2016-10-27 12:44:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    1. ConfigurationManager的命名空间:using System.Configuration;
    2. To be able to save you have to use a configuration object returned by the OpenExeConfiguration Method
    1. //Create the object
    2. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    3. //make changes
    4. config.AppSettings.Settings["Username"].Value = txtUsername.Text;
    5. config.AppSettings.Settings["Password"].Value = txtPassword.Text;

    6. //save to apply changes
    7. config.Save(ConfigurationSaveMode.Modified);
    8. ConfigurationManager.RefreshSection("appSettings");
    复制代码


    3. When you run your application with F5,
    your code is compiled,
    the executable is copied to the bin or bin\Debug subdirectory of your source code directory,
    your app.config is copied as yourexecutable.exe.config into that directory, and
    your executable is started in that directory.
    Thus, your application uses the yourexecutable.exe.config in the bin or bin\Debug directory, and it is there that ConfigurationManager saves the changes, not in your source code directory. This won't be an issue after deploying your application, because then, changes will go to yourexecutable.exe.config in the deployment directory, which is what you want.
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|Silian Lighting+ ( 蜀ICP备14004521号-1 )

    GMT+8, 2024-4-28 04:44 , Processed in 1.062500 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表