ASP.NET 2.0 读取配置文件[INI]
2007-05-30 13:40
701 查看
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 {
41 if (FilePath.Length == 0)
42 {
43 throw new Exception("没有设置路径");
44 }
45 StringBuilder sb = new StringBuilder();
46 int i = GetPrivateProfileString(strSection, strKey, "", sb, 255, this.FilePath);
47 return sb.ToString();
48 }
49 }
2. 后台调用文件 INIFile.aspx.cs 代码
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 //Read
4 INIFILE ini = new INIFILE();
5 ini.FilePath = Request.PhysicalApplicationPath + "ini.ini";
6 string strReturnValue = ini.ReadValue("Annabelle", "Time");
7 Response.Write(strReturnValue);
8
9 //Write
10 INIFILE ini = new INIFILE();
11 ini.FilePath = Request.PhysicalApplicationPath + "ini.ini";
12 string strReturnValue = ini.ReadValue("Annabelle", "Time");
13 Response.Write(strReturnValue);
14 ini.WriteValue("Annabelle", "Time", "0");
15 strReturnValue = ini.ReadValue("Annabelle", "Time");
16 Response.Write(strReturnValue);
17 }
(三). 示例代码下载
http://www.cnblogs.com/Files/ChengKing/ReadSettingFile.rar
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1534403
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 {
41 if (FilePath.Length == 0)
42 {
43 throw new Exception("没有设置路径");
44 }
45 StringBuilder sb = new StringBuilder();
46 int i = GetPrivateProfileString(strSection, strKey, "", sb, 255, this.FilePath);
47 return sb.ToString();
48 }
49 }
2. 后台调用文件 INIFile.aspx.cs 代码
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 //Read
4 INIFILE ini = new INIFILE();
5 ini.FilePath = Request.PhysicalApplicationPath + "ini.ini";
6 string strReturnValue = ini.ReadValue("Annabelle", "Time");
7 Response.Write(strReturnValue);
8
9 //Write
10 INIFILE ini = new INIFILE();
11 ini.FilePath = Request.PhysicalApplicationPath + "ini.ini";
12 string strReturnValue = ini.ReadValue("Annabelle", "Time");
13 Response.Write(strReturnValue);
14 ini.WriteValue("Annabelle", "Time", "0");
15 strReturnValue = ini.ReadValue("Annabelle", "Time");
16 Response.Write(strReturnValue);
17 }
(三). 示例代码下载
http://www.cnblogs.com/Files/ChengKing/ReadSettingFile.rar
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1534403
相关文章推荐
- (转)ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- [导入]ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- ASP.NET 2.0 读取配置文件[INI](示例代码下载)
- 一起谈.NET技术,asp.net程序来读取多语言版本Ini配置文件
- asp.net 2.0 中加密web.config 文件中的配置节
- ASP.NET CORE入门之读取Json配置文件
- asp.net core轻松入门之MVC中Options读取配置文件
- ASP.Net 2.0的Web.config配置和读取
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0中,对网站配置文件(web.cofig)进行加密(摘)
- asp.net 2.0 读写配置文件
- asp.net中配置文件web.config文件的读取和修改