国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET 2.0 讀取配置文件[INI](示例代碼下載)

2024-07-10 13:06:07
字體:
來源:轉載
供稿:網友

(一). 功能

         操作配置文件[*.ini]類

(二). 代碼

     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     {
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


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 区。| 霸州市| 噶尔县| 潍坊市| 永昌县| 涡阳县| 张掖市| 固原市| 汉中市| 招远市| 株洲县| 永川市| 海林市| 红原县| 保亭| 东兰县| 万载县| 西青区| 沙雅县| 双城市| 宾川县| 綦江县| 基隆市| 大港区| 海盐县| 托克托县| 荔浦县| 内黄县| 洪江市| 东光县| 同仁县| 洪洞县| 奉节县| 长治市| 名山县| 潢川县| 唐河县| 青川县| 同江市| 通州市| 灌阳县|