• C# 读写Ini 文件


    代码如下:

     

    1. # 读写 Ini 文件   
    2. using System.Runtime.InteropServices;  
    3. public class IniFile  
    4. {  
    5.     private string path;  
    6.  
    7.     public IniFile(string iniPath)  
    8.     {  
    9.         this.path = iniPath;  
    10.     }  
    11.  
    12.     [DllImport("kernel32")]  
    13.     private static extern int GetPrivateProfileString  
    14.         (string section, string key, string def, StringBuilder retVal, int size, string filePath);  
    15.     [DllImport("kernel32")]  
    16.     private static extern long WritePrivateProfileString  
    17.         (string section, string key, string val, string filePath);  
    18.  
    19.     public string IniReadValue(string section, string key)  
    20.     {  
    21.         try 
    22.         {  
    23.             StringBuilder retVal = new StringBuilder(0xff);  
    24.             if (GetPrivateProfileString(section, key, "", retVal, 0xff, this.path) == 0)  
    25.             {  
    26.                 return string.Empty;  
    27.             }  
    28.             return retVal.ToString();  
    29.         }  
    30.         catch (Exception exception)  
    31.         {  
    32.             return exception.ToString();  
    33.         }  
    34.     }  
    35.  
    36.     public void IniWriteValue(string Section, string Key, string Value)  
    37.     {  
    38.         WritePrivateProfileString(Section, Key, Value, this.path);  
    39.     }  
  • 相关阅读:
    bootstrap-table对前台页面表格的支持
    解决拦截器对ajax请求的的拦截
    jQuery获取鼠标事件源(万能)
    HtmlAgilityPack 处理通配的contains
    【转】XPath的学习
    在IIS服务器上部署svg/woff/woff2字体
    【转】万网域名查询接口(API)的说明
    html5和css3的常用参考网
    【转】Xml序列化
    C#序列化s实体类成Xml,去除空格、换行符以及命名空间
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3569064.html
Copyright © 2020-2023  润新知