C#读取ini文件方法,实质是使用C++的库

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/leolinsheng/article/details/50602886

C#读取ini文件方法,实质是使用C++的库

[DllImport("kernel32")]
        public static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
        [DllImport("kernel32")]
        public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filePath);
//读取ini配置文件
        public static string GetIniValue(string strFilePath, string key)
        {
            if (!File.Exists(strFilePath)) return string.Empty;
            StringBuilder temp = new StringBuilder(1024);
            string strSec = "GISDownLoad";
            HVIC.Library.Win32API.GetPrivateProfileString(strSec, key, "", temp, 1024, strFilePath);
            return temp.ToString();
        }

        //写入ini配置文件
        public static void WriteIniValue(string strFilePath,string key,string value)
        {
            string strSec = "GISDownLoad";
            if (!string.IsNullOrEmpty(value))
            {
                HVIC.Library.Win32API.WritePrivateProfileString(strSec, key, value.Trim(), strFilePath);
            }
        }

猜你喜欢

转载自blog.csdn.net/leolinsheng/article/details/50602886
今日推荐