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静态变量和实例变量的区别
海量数据处理:十道面试题与十个海量数据处理方法总结
持有对象(看think in java)
在myeclipse9.0中安装插件SVN(掌握通用安装插件的方法)
java的垃圾回收机制(think in java学习总结):
CSS控制文本自动换行
jquery获得select option的值 和对select option的操作
JS操作table!js table行数
jquery ui datepicker 只能选今天以后的日期
原文地址:https://www.cnblogs.com/tommyli/p/732328.html
最新文章
欲望的来源
12星座宿命姻缘配对
C#基础—— check、lock、using语句归纳
智慧是第一生命
asp.net底层架构(收藏)
《写给大家看的设计书》封面设计基本要求
《写给大家看的设计书》内容介绍(供设计时参考)
《写给大家看的设计书》封面征集大赛
FLASH透明背景代码大全
二级图片导航效果
热门文章
《转载》IE6/7绝对定位元素神秘消失或被遮挡的解决
jQuery hover 与 mouseover 与mouseout 的区别
每个浏览器不同之处 bug
CSS Hack 汇总快查
如何解决IE6/7绝对定位元素神秘消失或被遮挡的方法
opacity:0.99;
排序算法小结
二维数组中的查找
SSH 框架的搭建
何谓海量数据处理?
Copyright © 2011-2022 走看看