C# - 使用ConfigurationManager保存数据到App.config
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
binorbin\Debugsubdirectory of your source code directory, - your
app.configis copied asyourexecutable.exe.configinto 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的更多相关文章
- 浏览器保存数据给app读取
https://www.jianshu.com/p/239bab24d249 https://www.jianshu.com/p/43f8a81dd8ca
- C#读写操作app.config中的数据
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connecti ...
- App.config配置详解
经上一篇文章https://www.cnblogs.com/luna-hehe/p/9104701.html发现自己对配置文件很是不了解,同样还是查了半天终于发现另一片宝贵文档https://www. ...
- 配置文件——App.config文件读取和修改
作为普通的xml文件读取的话,首先就要知道怎么寻找文件的路径.我们知道一般配置文件就在跟可执行exe文件在同一目录下,且仅仅在名称后面添加了一个.config 因此,可以用Application.Ex ...
- app.config的坑
C# C/S程序一般通过ConfigurationManager类来读取app.config,其中有个坑爹的地方是ConfigurationManager类自带缓存,就如Windows服务来说,除非重 ...
- app.config/web.config配置文件增删改
一.概述 应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和 ...
- 连接App.config
ConfigurationManager.AppSettings["AdminName"]; 连接App.config的字符
- 如何修改 app.config 的配置信息
如何修改 app.config 的配置信息 收藏 最问这个问题的人有点多,其实 .Net 提供了这样的功能我们可以在 app.config 中 userSettings 节点中保存我们的应用程序设置信 ...
- C# 对 App.config的appSettings节点数据进行加密
.NET平台下的Winform和Asp.net的配置文件默认都是明文保存的,本文使用的是.Net自身如何加密配置文件,不包含自定义的加密规则 但.Net是提供了直接对配置文件加密的功能的,使用.Net ...
随机推荐
- 修改文件所有者 chown
将upload目录权限改为777,sudo chmod 777 upload,再测试上传功能成功.但这种修改权限的方法并不安全.故可以改upload目录的拥有者为www-data(即apache) ...
- struts2.1.3之后使用自定义Filter
struts2中 ActionContextCleanUp, StrutsPrepareAndExecuteFilter, StrutsPrepareFilter,StrutsExecuteFilte ...
- [ES6] Module export
Default export: Default export is easy way to export a function to outside module. //flash-message.j ...
- PLSQL Developer安装(Oracle11g+win7_64bit)
1)安装Oracle 11g 64位 2)安装32位的Oracle客户端( instantclient-basic-win32-11.2.0.1.0)下载地址:http://www.oracle.co ...
- js框架页跳转
1.跳出框架,在父页面. <script type="text/javascript"> window.parent.frames.location.href=&quo ...
- HQL查询
HQL ,Hibernate Query Language ,是Hibernate查询语言,不直接操作数据表,而是操作实体类,根据实体类和对应数据表中的映射关系,查找数据. 下面是hql的基本步骤: ...
- asp.net读取Excel中的数据问题
1.Microsoft.ACE.OLEDB.12.0 与Microsoft.Jet.OLEDB.4.0 在通过ADO对Excel对象进行连接时(此时Excel则认为是一个数据源),需要配置对Exc ...
- 打印HTML页面部分区域javascript代码
function preview(oper) { if (oper < 10) { bdhtml = window.document.body.innerHTML; //获取当前页的html代码 ...
- [Leetcode][001] Two Sum (Java)
题目在这里: https://leetcode.com/problems/two-sum/ [标签]Array; Hash Table [个人分析] 这个题目,我感觉也可以算是空间换时间的例子.如果是 ...
- arm+linux 裸机环境搭建之初试minicom+dnw烧写uboot
下面的步骤将会实现在linux下面使用dnw+minicom来烧写uboot 一.安装minicom 下载地址:http://download.csdn.net/detail/king_bingge/ ...