读写INI:

 首先,得到当前exe的运行路径  
  ApplicationPath   =   Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);  
  下面是操作INI文件的类  

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;

namespace Ini
{
    
///   <summary>   
    
///   Ini的摘要说明。   
    
///   </summary>   

    public class IniFile
    
{

        
public string path;

       
写入信息文件

        
读取信息文件

        
public IniFile(string INIPath)
        
{
            path 
= INIPath;
        }


        
public void IniWriteValue(string Section, string Key, string Value)
        
{
            WritePrivateProfileString(Section, Key, Value, 
this.path);
        }


        
public string IniReadValue(string Section, string Key)
        
{
            
return GetPrivateProfileString(Section, Key, ""this.path);
        }


    }

}

使用方法  
  写信息文件  
  IniFile   NewIni   =   new   IniFile(ApplicationPath   +   "\\Test.ini");  
  NewIni.IniWriteValue("测试信息","测试一","1");  
   
  读取  
  IniFile   NewIni   =   new   IniFile(ApplicationPath   +   "\\Test.ini");  
  string   a   =   NewIni   .IniReadValue("测试信息","测试一");  
   
  读取结果  
  a   =   1

 备注:以上代码在HP   2490(WM5)上测试通过

 

 


 

 

posted on 2009-11-04 10:43  Kein  阅读(1229)  评论(0编辑  收藏  举报