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
>
查看全文
相关阅读:
裸裸的spfa~嘿嘿嘿!
睡前1小时数学系列之-整除
拓扑排序1.奖金
拓扑排序
SCU 1095运送物资(最短路)
POJ1158 城市交通Traffic lights IOI 1999 (最短路)
POI0109 POD (最短路)
HN0I2000最优乘车 (最短路变形)
FOJ1205 小鼠迷宫问题 (BFD+递推)
CJOI 05新年好 (最短路+枚举)
原文地址:https://www.cnblogs.com/tommyli/p/732328.html
最新文章
第4章 字符串操作与正则表达式
第3章 使用数组
第2章 数据的存储与检索
第1章 PHP快速入门
1. LAMP----PHP开发环境搭建(Win)
#js#简单的在线计算器
CF Round #355 Div.2
CF Round #354 Div.2
CF Round #353 Div.2
#数论-模运算#POJ 1150、1284、2115
热门文章
openjudge 1805碎纸机 解析报告
openjudge 2971:抓住那头牛 解题报告
openjudge 1789算24 解析报告
openjudge 1792 迷宫 解析报告
vim命令大全(转)
uva10603 解题报告
uva1354 天平难题 解题报告
刺猬的玻璃心博客目录:
睡前1小时数学系列之-同余及其证明
spfa-codevs1021题解
Copyright © 2011-2022 走看看