读写配置文件的方法
2014-02-08 19:58
225 查看
读写配置文件的方法
用户配置保存在 下。
<appSettings>
<add key="test" value="test Value" />
</appSettings>
当在交互模式下运行时,配置保存到 fsi.exe.Config 中,在 C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0
而在正常运行时,会保存到 .EXE 文件相同的目录下,其文件名与 .EXE 的主文件名相同。
#r "System.Configuration.dll"
open System.Configuration
let SetValue key value =
let config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
if config.AppSettings.Settings.[key] = null then
config.AppSettings.Settings.Add(key, value)
else
config.AppSettings.Settings.[key].Value <- value
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
let GetValue key =
let config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
if config.AppSettings.Settings.[key] = null then
""
else
config.AppSettings.Settings.[key].Value
SetValue "test" "test Value"
GetValue "test"
用户配置保存在 下。
<appSettings>
<add key="test" value="test Value" />
</appSettings>
当在交互模式下运行时,配置保存到 fsi.exe.Config 中,在 C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0
而在正常运行时,会保存到 .EXE 文件相同的目录下,其文件名与 .EXE 的主文件名相同。
#r "System.Configuration.dll"
open System.Configuration
let SetValue key value =
let config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
if config.AppSettings.Settings.[key] = null then
config.AppSettings.Settings.Add(key, value)
else
config.AppSettings.Settings.[key].Value <- value
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
let GetValue key =
let config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
if config.AppSettings.Settings.[key] = null then
""
else
config.AppSettings.Settings.[key].Value
SetValue "test" "test Value"
GetValue "test"
相关文章推荐
- C# 读写App.config配置文件的方法
- Autohotkey的配置文件读写方法ini
- [C#] 读写App.config配置文件的方法
- Python读写配置文件的方法
- VS2005中读写配置文件(方法一)(转载)
- Andorid读写全局配置文件的方法
- VS2005中读写配置文件(方法一)(转载)
- python读写ini配置文件方法实例分析
- C# 读写App.config配置文件的方法
- VS2005中读写配置文件(方法二)
- C#读写config配置文件的方法
- 一种简便实效的配置文件读写方法
- Java Web:JSON 作为配置文件,简单读写的方法
- C# 读写App.config配置文件的方法
- [C#] 读写App.config配置文件的方法
- c#中进行读写配置文件的方法
- .net下读写配置文件app.config方法
- 一种简便实效的配置文件读写方法
- Python读写配置文件的方法
- C# 读写App.config配置文件的方法