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. 集成容联:Warning! ivar size mismatch in PSUICollectionView_ - can't change the superclass.解决办法

    这个警报其实是无影响的. 解决方案: PSTCollectionView.m  的  char filler[200]   替换成char filler[300]

  2. mybatis简单应用(基于配置文件)

    本文主要介绍了如何使用mybatis进行简单的数据库操作.本人使用的是mybatis3.05. 1.创建数据库表(User表) CREATETABLE `NewTable` (`userId` big ...

  3. Win32<CreatFile>

    CreateFile函数详解 CreateFile The CreateFile function creates or opens the following objects and returns ...

  4. 监听tableview的点击事件

    // 监听tablview的点击事件 - (void)addAGesutreRecognizerForYourView { UITapGestureRecognizer *tapGesture = [ ...

  5. mybati的存储过程

    这里我就以的存储过程为例,大家一起学习一下,

  6. Asp.Net WebApi+Microsoft.AspNet.WebApi.Core 启用CORS跨域访问

    WebApi中启用CORS跨域访问 1.安装 Nugget包Microsoft.AspNet.WebApi.Cors This package contains the components to e ...

  7. Asp.Net WebAPI 通过HttpContextBase获取请求参数

    WEBAPI中的Request是HttpRequestMessage类型,不能像Web传统那样有querystring和from 方法接收参数,而传统的HttpReqest的基类是HttpReqest ...

  8. Swift--集合类型 数组 字典 集合

    数组 1.创建一个数组 var someInts = [Int]()空数组 someInts = []清空 var threeDoubles = Array(repeating: 0.0, count ...

  9. self和super之间的区别

    关于 self 和 super 之间的区别, 首先要了解  1, self  是什么 :super 是什么.2,[ super init] 做什么.3,为什么要 self =  [super init ...

  10. java基础day7

    1/匿名类对象:创建类的对象是匿名的. 比如说new Circle():就是一个匿名类对象. 匿名类对象只能使用一次. 2/形参:声明方法时,方法小括号内的参数 实参:调用方法是,实际传入的参数的值 ...