ASP.NET 2.0读取配置文件示例代码
1. 核心类文件 INIFILE.cs 代码&n M5yt#~H ^JHz/MO1 /// <summary>2 /// INIFILE 操作类3 /// </summary>4 public class INIFILE5 {6 [DllImport("kernel32")]7 private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);89 [DllImport("kernel32")]10 private static extern int GetPrivateProfileString(string section,string key,string def, StringBuilder retVal,int size,string filePath);1112 //要访问的文件路径13 private string strFilePath;1415 public string FilePath16 {17 get { return strFilePath; }18 set { strFilePath = value; }19 }2021 public INIFILE()22 {23 }2425 public INIFILE( string strFilePath )26 {27 this.strFilePath = strFilePath;28 }2930 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 }3839 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 } H1E"\.F:Xv
2. 后台调用文件 INIFile.aspx.cs 代码'jJ+i@cl&M