首页 > 其他 > 详细

C#访问配置文件

时间:2014-05-18 20:14:55      阅读:469      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace HelloCSharp
{
    //[section]
    //key=value
    //
    class IniHelper
    {
        /// <summary>
        /// ini文件的路径
        /// </summary>
        private string filePath;


        [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);

        public IniHelper(string filePath)
        {
            this.filePath = filePath;
        }

        public void IniWriteValue(string section, string key, string val)
        {
            WritePrivateProfileString(section, key, val, filePath);
        }

        public string IniReadValue(string section, string key)
        {
            StringBuilder temp = new StringBuilder(500);
            GetPrivateProfileString(section, key, "", temp, 500, filePath);
            return temp.ToString();
        }
    }
}
bubuko.com,布布扣

 

C#访问配置文件,布布扣,bubuko.com

C#访问配置文件

原文:http://www.cnblogs.com/dan-jacky/p/3732524.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!