1. ConfigurationManager的命名空间:using System.Configuration;

2. To be able to save you have to use a configuration object returned by the OpenExeConfiguration Method

//Create the object
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //make changes
config.AppSettings.Settings["Username"].Value = txtUsername.Text;
config.AppSettings.Settings["Password"].Value = txtPassword.Text; //save to apply changes
config.Save(ConfigurationSaveMode.Modified);
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.

C# - 使用ConfigurationManager保存数据到App.config的更多相关文章

  1. 浏览器保存数据给app读取

    https://www.jianshu.com/p/239bab24d249 https://www.jianshu.com/p/43f8a81dd8ca

  2. C#读写操作app.config中的数据

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

  3. App.config配置详解

    经上一篇文章https://www.cnblogs.com/luna-hehe/p/9104701.html发现自己对配置文件很是不了解,同样还是查了半天终于发现另一片宝贵文档https://www. ...

  4. 配置文件——App.config文件读取和修改

    作为普通的xml文件读取的话,首先就要知道怎么寻找文件的路径.我们知道一般配置文件就在跟可执行exe文件在同一目录下,且仅仅在名称后面添加了一个.config 因此,可以用Application.Ex ...

  5. app.config的坑

    C# C/S程序一般通过ConfigurationManager类来读取app.config,其中有个坑爹的地方是ConfigurationManager类自带缓存,就如Windows服务来说,除非重 ...

  6. app.config/web.config配置文件增删改

    一.概述 应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和 ...

  7. 连接App.config

    ConfigurationManager.AppSettings["AdminName"]; 连接App.config的字符

  8. 如何修改 app.config 的配置信息

    如何修改 app.config 的配置信息 收藏 最问这个问题的人有点多,其实 .Net 提供了这样的功能我们可以在 app.config 中 userSettings 节点中保存我们的应用程序设置信 ...

  9. C# 对 App.config的appSettings节点数据进行加密

    .NET平台下的Winform和Asp.net的配置文件默认都是明文保存的,本文使用的是.Net自身如何加密配置文件,不包含自定义的加密规则 但.Net是提供了直接对配置文件加密的功能的,使用.Net ...

随机推荐

  1. lua 加密

    项目要求对lua脚本进行加密,查了一下相关的资料 ,得知lua本身可以使用luac将脚本编译为字节码(bytecode)从而实现加密,试了一下,确实可行.下面是使用原生的lua解释器编译字节码:1.新 ...

  2. django: template using & debug

    模板的作用方法有如下三种: blog/views.py: from django.template import loader, Context, Template from django.http ...

  3. MVC第一节 配置

    1.View中的页面设置为起始页后导致404找不到文件. 解决方案:右键属性,把特定页置为空. 2.新建的MVC项目会把系统默认的浏览器作为浏览方式,如果想要改变的话.可以在项目中新建一个webFor ...

  4. 基于java callable及future接口解决生产者消费者问题

    这两天复习java线程时,把java里面的线程基本知识点与jdk1.5以后新添加的一些类的使用都了解了一下,借用生产者消费者的问题来将他们实践一下. 题目:(题目在csdn一大牛的空间找的) 生产者- ...

  5. JQuery结合Ajax实现双击Table表格,使Table变成可编辑,并保存到数据库中

    本文属于原创,转载请标明出处! 近期在做项目时,要实现通过双击Table表格的TR,使Table行变成可编辑,来实现修改数据并保存到数据库中的功能,无需多说,直接贴代码吧.希望能得到各位同仁指正. f ...

  6. Sql Server 连接池及其用法

    其实我们一直在使用SqlServer的连接池.在连接字符串中,Pooling为是否启用连接池,默认值为true,表示启用. 与连接池相关的两个重要参数是 Min Pool Size和 Max Pool ...

  7. CSS实现三角形效果

    类似三角形的形状的元素在网页中可能会用到,我们可以用图片或者CSS元素达到我们想要的效果.这里讲一下是讲自己使用HTML+CSS实现三角形的方式. 为了能够熟悉的使用HTML+CSS构建三角形,我们首 ...

  8. Grunt使用心得

    1.安装npm 2.安装CLI ( npm install -g grunt-cli) 3.安装grunt (npm install grunt --save-dev) 4.添加gruntfile.j ...

  9. MySQL查询指定时间的数据

    user_event :用户事件表 create_time :表中存储时间的字段 #获取当月数据 SELECT * FROM user_event WHERE DATE_FORMAT(create_t ...

  10. Python socket 广播信息到所有连接的客户端

    Python3,多线程,多客户端,广播数据 #!/usr/bin/env python3 import time import threading import queue import socket ...