ConfigurationManager读取和写入

  提供对客户端应用程序配置文件的访问
  通过引入System.Configuration.dll可以用ConfigurationManager类来读取项目中保存在App.config中的配置信息,如:
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Number0" value=""/>
<add key="Number1" value=""/>
<add key="Number2" value=""/>
<add key="Number3" value=""/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
 
后台:
 
读取数据:  
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int i = int.Parse(ConfigurationManager.AppSettings["Number2"]);
this.txtMsg.Text = i.ToString();
}
写入数据: 
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfa.AppSettings.Settings["Number2"].Value = "";
cfa.Save();
 

ConfigurationManager的更多相关文章

  1. ASP.net 使用ConfigurationManager获取连接字符串

    在解决方案资源管理器里右键单击解决方案选择“添加引用”,并且从 .net 中找到 System.Configuration 引用它 在项目的web.config文件中添加 <connection ...

  2. 如何让ConfigurationManager打开任意的配置文件

    VisualStudio的配置文件很好很强大,用来保存数据库连接字符串或键值对都非常方便,只需要通过ConfigurationManager的ConnectionStrings或AppSettings ...

  3. System.Configuration引用后ConfigurationManager方法用不了

    System.Configuration引用后ConfigurationManager方法却用不了,提示没有引用 需手动添加引用 项目-引用-右击-添加引用-找到System.Configuratio ...

  4. ASP.NET 系列:单元测试之ConfigurationManager

    通过ConfigurationManager使用.NET配置文件时,可以通过添加配置文件进行单元测试,虽然可以通过测试但达不到解耦的目的.使用IConfigurationManager和Configu ...

  5. Visual Studio 当前上下文中不存在名称“ConfigurationManager”

    Visual Studio调试出现错误:当前上下文中不存在名称“ConfigurationManager” 解决方法: 1.System.Configuration引用这个dll参考:http://k ...

  6. 使用ConfigurationManager类读写配置文件

    使用ConfigurationManager类 读写配置文件app.config,以下为代码: view plaincopy to clipboard print? using System; usi ...

  7. 『随笔』C# 程序 修改 ConfigurationManager 后,不重启 刷新配置

    基本共识: ConfigurationManager 自带缓存,且不支持 写入. 如果 通过 文本写入方式 修改 配置文件,程序 无法刷新加载 最新配置. PS. Web.config 除外:Web. ...

  8. 《ASP.NET1200例》当前上下文中不存在名称configurationmanager

    当前上下文中不存在名称ConfigurationManager的解决方法 今晚做项目在DBHelper.cs类中的数据库连接要改到web.config里面调用,结果在编译的时候却发现提示错误: 当前上 ...

  9. 让ConfigurationManager打开任意的配置文件

    VisualStudio的配置文件很好很强大,用来保存数据库连接字符串或键值对都非常方便,只需要通过ConfigurationManager的ConnectionStrings或AppSettings ...

  10. 用ConfigurationManager读取和修改配置文件

    为了方便有时我们会把一些简单的配置的信息放入web.config文件里. 放到appSettings添加key   value等信息. ConfigurationManager.AppSettings ...

随机推荐

  1. 前端项目打包工具weexpack的安装

    最下面是本人安装时候的系统环境,本篇文章只限于参考,不一定非得是这样,原因你懂得. 打包的过程中出现的问题 1.执行到weexpack run android的时候,到了resolving class ...

  2. 初探angluar_01 目录结构分析及初始化项目

    简单说明:angular是模块化的,因此所有功能功能都属于组件 一.目录结构 e2e 端到端的测试目录  用来做自动测试的 node_modules 安装地依赖存放目录,package.json里安装 ...

  3. C#委托总结-入门篇

    1,概念:委托类型表示对具有特定参数列表和返回类型的方法的引用. 通过委托,可以将方法视为可分配给变量并可作为参数传递的实体. 委托是引用类型,可以把它看作是用来存方法的一种类型.比如说类型strin ...

  4. 使用filter进行登录验证,并解决多次重定向问题

    最近在做关于filter登录验证的功能,防止未登录的用户直接通过地址进入系统 LoginFilter类:继承Filter接口 package com.ss.filter; import java.io ...

  5. CRT和EXCRT简单学习笔记

    中国剩余定理CRT 中国剩余定理是要求我们解决这样的一类问题: \[\begin{cases}x\equiv a_1\pmod {b_1} \\x\equiv a_2 \pmod{b_2}\\...\ ...

  6. JQuery Mobile - 需要注意问题!

    一,JQuery Mobile 和 JQuery 版本对接,一定要选用和当前JQuery Mobile 对应版本的JQuery . 二,在台式机的模拟器和真机中的显示结果可能不一样.我在台式机中使用的 ...

  7. Memoization-329. Longest Increasing Path in a Matrix

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  8. asp.net mvc 5 初体验

    参考:http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started 1. 新建 ASP.Net Web 应用程序,跟着向导一路 ...

  9. redis升级注意事项

    新版本redis读取 旧版本redis的rdb , aof 使用新版本redis备份rdb , aof操作系统级别备份 rdb , aof重启redis测试 新版本redisrdb , aof 能否读 ...

  10. Fiddler工具详细介绍

    百度看到Fiddler工具的详细介绍,转载收藏,侵权删,原文地址:http://blog.csdn.net/qq_21445563/article/details/51017605 前部分讲解Fidd ...