INI文件的读写

 public class INIoperation
    {
        string inipath = Utils.GetMapPath("/Integration/Sync/set.ini");
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        /// <summary>
        /// 读取配置ini文件
        /// </summary>
        /// <param name="Section">配置段</param>
        /// <param name="Key"></param>
        /// <param name="innpath">存放物理路径</param>
        /// <returns></returns>
        public string IniReadValue(string Section, string Key, string innpath)
        {
            StringBuilder temp = new StringBuilder(500);
            GetPrivateProfileString(Section, Key, "", temp, 500, inipath);
            return temp.ToString();
        }
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        /// <summary>
        /// 写入ini文件的操作
        /// </summary>
        /// <param name="Section">配置段</param>
        /// <param name="Key"></param>
        /// <param name="Value">键值</param>
        /// <param name="inipath">物理路径</param>
        public void IniWriteValue(string Section, string Key, string Value,string inipath)
        {
            WritePrivateProfileString(Section, Key, Value, inipath);
        }
   
    }  


 

 

posted @ 2016-04-12 09:16  时光吹老了好少年  阅读(262)  评论(0编辑  收藏  举报