101 VB.NET Samples - How-To Configuration Settings
来源:互联网 发布:淘宝的优惠券可靠吗 编辑:程序博客网 时间:2024/05/04 16:19
ConfigurationSettings.AppSettings[""] 只是程序初始化的时候获得数据,之后不再从config文件获得。直接使用的是初始化获得的数据。Confile文件的格式大致是这样的:
<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="lblValue.Text" value="(empty)" />
<add key="hello" value="good" />
</appSettings>
</configuration>
用的的类有AppSettings和AppSetting类
AppSettings里的函数:Save,Add,RemoveByKey
下面是MS例子里的说明文档:
.NET Framework: Configuration Settings
This sample demonstrates how to read and write to an application's configuration file appSettings section.
Featured Highlights
.NET applications support custom XML configuration files out-of-the box. You simply add an app.config file to your solution via Project | Add New Item and select the Application Configuration File option. The item will be added to your bin directory each time you compile. You can then add your own settings to this file so that users or administrators can adjust an application's settings by simply adjusting a text file.
You can specifiy settings for individual controls that you want exposed via the configuration file. You simply add a Dynamic Property for any control value you want exposed. Examine the lblValue control for an example. Any of the dynamic property values defined in the appSettings section of configuration file will be loaded at runtime. You can access the values via the ConfigurationSettings.AppSettings. However, the NameValueCollection object exposed is read only. In addition, the settings are only loaded once at application startup.
If you want to be able to make changes to the file at runtime, you will need use the classes in the System.Xml namespace. This sample exposes two classes to let you do this:
- AppSettings which wraps the configuration file's appSettings section
- AppSetting which represents a single name/value pair item
AppSettings allows you to add, retrieve, update, and remove name/value pairs from the configuration file. It does this by wrapping access to the file via an XmlDocument instance. In addition it supports saving the changes manually or via an auto-save feature. Finally, the class implements IEnumerable to provide For..Each support.
Requirements
Requires the Trial or Release version of Visual Studio .NET Professional (or greater).
Running the Sample
Start the program and examine the data exposed. Change the file manually and then use the functions on the Custom tab to see the changes. Or, use the command options exposed under the Custom tab.
- 101 VB.NET Samples - How-To Configuration Settings
- 101 VB.NET Samples - How-To Service Manager
- 101 VB.NET Samples: Getting System & Environment Information
- 101 VB.NET Samples --XML文件的处理
- How to save brightness settings?
- How to read settings.db
- How to use Configuration Catalog
- Tomcat SSL Configuration HOW-TO
- HOW TO:获取硬盘物理序列号(VB.NET)
- How to Open a Text File in VB .NET
- How to Create Dynamic Settings Pages
- How to add extended Quick Settings
- How to edit Sublime Text build settings?
- How to run the qualcomm AR samples on Android
- How to use ArcGIS samples for help running the sample
- How to Change .NET Configuration Files at Runtime (including for WCF)
- How To: Use DPAPI to Encrypt and Decrypt Data (C#/VB.NET)
- Trac configuration: How to start the Trac
- SQL Server 2000中的触发器使用
- MS SQL 2005中的系統表探索(System Base Tables)(II)
- AJAX与微软的新方案
- ERP-企业管理的利器(载自http://blog.csdn.net/whchen处)
- 一个值得保留的事件说明代码
- 101 VB.NET Samples - How-To Configuration Settings
- 如何不通过其他工具,把图片、声音等存储到sql中(载自http://blog.csdn.net/softj处)
- 101 VB.NET Samples: Getting System & Environment Information
- 在web开发中的三个层次使用事务
- 『传媒江湖』 [其他]14岁女孩被公交售票员掐死 媒体失语遭网
- 上班时候好好工作
- [原创]C指针应用常见缪误
- 压缩日志及数据库文件大小(载自http://blog.csdn.net/softj处)
- 怎样处理好同寝室同学之间的关系