惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - lining

输出的客户端 - lining - 博客园 List<T> - lining - 博客园 DateTime 赋空值 配色达人速成 批处理文件,删除文件及文件夹 - lining - 博客园 Source Code中pfx的密码 查找所有有某一列的表 用例的获得 如何oracle调试存储过程 C# 中String 和 string 有什么区别 ora-00997:非法使用LONG数据类型 oracle如何判断一个字符串是否为数字或日期 C# 中的计时器 populate a listbox on winform with values from database winform技巧,listbox绑定,value,text, - lining - 博客园 查看oracle执行计划 “Windows Workflow Foundation开发实战系列课程”中的数据库恢复 ASP.NET多语言版的开发 oracle数据导入导出imp/exp命令
如何修改 app.config 的配置信息
lining · 2010-08-25 · via 博客园 - lining

from-> http://blog.csdn.net/sabty/archive/2010/03/19/5395275.aspx

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

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

具体操作步骤:

1 添加您需要保存的变量名称。在你的项目上点击右键选“属性” -> "设置"。在设置界面中输入你需要的变量名称。如添加变量 UserName 和ConnectionString,见下图。

设置

添加完成后保存一下,我们会发现上面的内容实际是保存在 app.config 的 userSetting 节点下的。

  1. <?xml version="1.0" encoding="utf-8" ?> 
  2. <configuration> 
  3.     <configSections> 
  4.         <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
  5.             <section name="X.UserSettingDemo.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> 
  6.         </sectionGroup> 
  7.     </configSections> 
  8.      
  9.     <userSettings> 
  10.         <X.UserSettingDemo.Properties.Settings> 
  11.             <setting name="ConnetionString" serializeAs="String"> 
  12.                 <value /> 
  13.             </setting> 
  14.             <setting name="UserName" serializeAs="String"> 
  15.                 <value /> 
  16.             </setting> 
  17.         </X.UserSettingDemo.Properties.Settings> 
  18.     </userSettings> 
  19. </configuration> 

2 读取与保存上面在 app.config 中添加的 UserName, ConnectionString 变量。

  1. using System; 
  2. using System.Windows.Forms; 
  3. namespace X.UserSettingDemo 
  4.     public partial class Form1 : Form 
  5.     { 
  6.         public Form1() 
  7.         { 
  8.             InitializeComponent(); 
  9.         } 
  10.         private void Form1_Load(object sender, EventArgs e) 
  11.         { 
  12.             this.InitApperance(); 
  13.         } 
  14.         private void btnSave_Click(object sender, EventArgs e) 
  15.         { 
  16.             this.SaveUserSetting(); 
  17.         } 
  18.          
  19.          
  20.          
  21.         private void InitApperance() 
  22.         { 
  23.             this.txtUserName.Text = X.UserSettingDemo.Properties.Settings.Default.UserName; 
  24.             this.txtConnectionString.Text = X.UserSettingDemo.Properties.Settings.Default.ConnetionString; 
  25.         } 
  26.          
  27.          
  28.          
  29.         private void SaveUserSetting() 
  30.         { 
  31.             X.UserSettingDemo.Properties.Settings.Default.UserName = this.txtUserName.Text; 
  32.             X.UserSettingDemo.Properties.Settings.Default.ConnetionString = this.txtConnectionString.Text; 
  33.             X.UserSettingDemo.Properties.Settings.Default.Save(); 
  34.         } 
  35.     } 

示例代码下载地址:http://download.csdn.net/source/2142651

发表于 @ 2010年03月19日 10:03:00 | 评论( 0 ) | 举报| 收藏

旧一篇:Winform 中 DesignMode 返回值不正确的问题。 | 新一篇:如何将图片或其它文件保存到数据库中(C#)