zoukankan      html  css  js  c++  java
  • C#读写ini

    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;
     
    namespace helper
    {
     
        /// <summary> 
        /// ini文件读与写 
        /// </summary> 
        public class ClsIniFile
        {
            //文件INI名称 
            public string Path;
            ////声明读写INI文件的API函数 
            [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
            //类的构造函数,传递INI文件名 
            public ClsIniFile(string inipath){ Path = inipath; }
            /// <summary>
            /// 写入INI文件
            /// </summary>
            /// <param name="Section">配置节</param>
            /// <param name="Key">键名</param>
            /// <param name="Value">键值</param>
            public void IniWriteValue(string Section, string Key, string Value)
            {
                WritePrivateProfileString(Section, Key, Value, this.Path);
            }
     
            /// <summary>
            /// 读取制定INI文件键值
            /// </summary>
            /// <param name="Section">配置节</param>
            /// <param name="Key">键名</param>
            /// <returns></returns> 
            public string IniReadValue(string Section, string Key)
            {
                StringBuilder temp = new StringBuilder(255);
                int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.Path);
                return temp.ToString();
            }
        }
    }

    转载于:https://www.cnblogs.com/ruingking/p/7160601.html

  • 相关阅读:
    免费的mail server
    opensuse 11.2/11.3安装vmware server 1.0.10笔记
    cisco IOS 免费下载的地方
    自动打开最快镜像站
    [ZT]MSSQL清空或者压缩日志的方法
    Cisco路由器的安全配置方案[zt]
    CISCO2821系列路由器恢复密码
    RTorrent User Guide
    Asp.Net发送邮件详解
    C#在线生成网页缩略图
  • 原文地址:https://www.cnblogs.com/twodog/p/12139929.html
Copyright © 2011-2022 走看看