zoukankan
html css js c++ java
Config文件的操作
public
class
NSection : ConfigurationSection
{
public
NSection()
{
}
[ConfigurationProperty(
"
id
"
)]
public
int
ID
{
get
{
return
(
int
)
this
[
"
id
"
]; }
set
{
this
[
"
id
"
]
=
value; }
}
[ConfigurationProperty(
"
name
"
)]
public
string
Name
{
get
{
return
this
[
"
name
"
].ToString(); }
set
{
this
[
"
name
"
]
=
value; }
}
public
override
string
ToString()
{
StringBuilder sb
=
new
StringBuilder();
sb.AppendFormat(
"
id = {0};name = {1}
"
, ID, Name);
return
sb.ToString();
}
}
添加
NSection section
=
new
NSection();
section.ID
=
1
;
section.Name
=
"
Test
"
;
Configuration config
=
WebConfigurationManager.OpenWebConfiguration(
"
~
"
);
config.Sections.Remove(
"
nSection
"
);
config.Sections.Add(
"
nSection
"
, section);
config.Save();
}
修改
Configuration config1
=
WebConfigurationManager.OpenWebConfiguration(
"
~
"
);
NSection section1
=
config1.GetSection(
"
nSection
"
)
as
NSection;
section1.ID
=
2
;
section1.Name
=
"
Test2
"
;
config1.Save();
查看
Configuration config
=
WebConfigurationManager.OpenWebConfiguration(
"
~
"
);
AppSettingsSection appSection
=
(AppSettingsSection)config.GetSection(
"
appSettings
"
);
string
[] Keys
=
appSection.Settings.AllKeys;
for
(
int
i
=
0
; i
<
Keys.Length; i
++
)
{
Response.Write(Keys[i]
+
"
:
"
+
appSection.Settings[Keys[i]].Value
+
"
<br>
"
);
}
ConnectionStringSettingsCollection connectionStrings
=
WebConfigurationManager.ConnectionStrings;
for
(
int
i
=
0
; i
<
connectionStrings.Count; i
++
)
{
Response.Write(
string
.Format(
"
Name:{0}:Conn{1}Pro{2}<br>
"
, connectionStrings[i].Name, connectionStrings[i].ConnectionString, connectionStrings[i].ProviderName));
}
//
删除appSettings节点中的元素
appSection.Settings.Remove(
"
addkey1
"
);
//
修改appSettings节点中的元素
appSection.Settings[
"
addkey2
"
].Value
=
"
Modify key2's value
"
;
config.Save();
<
appSettings
>
<
add key
=
"
ConfigPath
"
value
=
"
~/Config/
"
/>
<
add key
=
"
UploadSavePath
"
value
=
"
~/uploads/
"
/>
<
add key
=
"
EncryptMethod
"
value
=
"
1
"
/>
<
add key
=
"
AppTimeOut
"
value
=
"
0
"
/>
<
add key
=
"
CookieName
"
value
=
"
UserLogin
"
/>
<
add key
=
"
MultiDomainName
"
value
=
""
/>
<
add key
=
"
EnableDomains
"
value
=
""
/>
<
add key
=
"
staticFileExt
"
value
=
"
.aspx
"
/>
<
add key
=
"
EnableLog
"
value
=
"
true
"
/>
<
add key
=
"
addkey2
"
value
=
"
Modify key2's value
"
/>
</
appSettings
>
<
connectionStrings
>
<
add name
=
"
Default
"
providerName
=
"
SqlClient
"
connectionString
=
"
server=FENGYUN;uid=sa;pwd=110110;database=CMS;
"
/>
</
connectionStrings
>
查看全文
相关阅读:
java基础-集合笔记
Spring工具类
XStream的基本使用
java之路径问题
Vue 动态组件渲染问题分析
watch案例解析(element-ui el-select 无法选中问题剖析)
v-if案例解析(element-ui form-item 结合 v-if 动态生成rule规则表单元素,表单无法验证问题剖析 )
Vue 虚拟Dom 及 部分生命周期初探
Android仿苹果版QQ下拉刷新实现(二) ——贝塞尔曲线开发"鼻涕"下拉粘连效果
AngularJs(SPA)单页面SEO以及百度统计应用(下)
原文地址:https://www.cnblogs.com/tommyli/p/732328.html
最新文章
Javascript 追本溯源
Remoting 的“传递的引用”理解
ChesFrame框架介绍
C#委托和事件本质
AppDomain.CurrentDomain.GetAssemblies()
用Elasticsearch做大规模数据的多字段、多类型索引检索
javascript单元测试框架mochajs详解
做一个gulp+webpack+vue的单页应用开发架子
自己实现一个javascript事件模块
nodejs中获取时间戳、时间差
热门文章
理解nodejs模块的scope
nodejs模块发布及命令行程序开发
npm package.json属性详解
浏览器中用JavaScript获取剪切板中的文件
this,你是谁?
java网络编程5-SSL
java网络编程4-ServerSocket
java网络编程3-Socket
java网络编程2-URL和URI
java网络编程1-查询Internet地址
Copyright © 2011-2022 走看看