- ·上一篇文章:模板类新人类,使用简单速度超快
- ·下一篇文章:2.3、实型AK-47“冲锋枪”
ASP.NET 2.0读取配置文件示例代码
1. 核心类文件 INIFILE.cs 代码
1 /// <summary>
2 /// INIFILE 操作类
3 /// </summary>
4 public class INIFILE
5 {
6 [DllImport("kernel32")]
7 private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
8
9 [DllImport("kernel32")]
10 private static extern int GetPrivateProfileString(string section,string key,string def, StringBuilder retVal,int size,string filePath);
11
12 //要访问的文件路径
13 private string strFilePath;
14
15 public string FilePath
16 {
17 get { return strFilePath; }
18 set { strFilePath = value; }
19 }
20
21 public INIFILE()
22 {
23 }
24
25 public INIFILE( string strFilePath )
26 {
27 this.strFilePath = strFilePath;
28 }
29
30 public void WriteValue(string strSection,string strKey,string strValue)
31 {
32 if (FilePath.Length == 0)
33 {
34 throw new Exception("没有设置路径");
35 }
36 WritePrivateProfileString(strSection, strKey, strValue, this.FilePath);
37 }
38
39 public string ReadValue(string strSection,string strKey)
40 {
1 /// <summary>
2 /// INIFILE 操作类
3 /// </summary>
4 public class INIFILE
5 {
6 [DllImport("kernel32")]
7 private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
8
9 [DllImport("kernel32")]
10 private static extern int GetPrivateProfileString(string section,string key,string def, StringBuilder retVal,int size,string filePath);
11
12 //要访问的文件路径
13 private string strFilePath;
14
15 public string FilePath
16 {
17 get { return strFilePath; }
18 set { strFilePath = value; }
19 }
20
21 public INIFILE()
22 {
23 }
24
25 public INIFILE( string strFilePath )
26 {
27 this.strFilePath = strFilePath;
28 }
29
30 public void WriteValue(string strSection,string strKey,string strValue)
31 {
32 if (FilePath.Length == 0)
33 {
34 throw new Exception("没有设置路径");
35 }
36 WritePrivateProfileString(strSection, strKey, strValue, this.FilePath);
37 }
38
39 public string ReadValue(string strSection,string strKey)
40 {


