没有现成的类,C#中都用XML的配置文件了,可以调用WINAPI实现,比如:
Private Declare Unicode Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileIntW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal nDefault As Int32, _
ByVal lpFileName As String) As Int32Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Int32, _
ByVal lpFileName As String) As Int32
 
 
这两个例子是VB的,C#简单修改即可

解决方案 »

  1.   

    给你个例子吧,刚好在手边
    [DllImport("kernel32.dll")]
    public static extern int GetPrivateProfileString(
    string lpAppName, // section name
    string lpKeyName, // key name
    string lpDefault, // default string
    string lpReturnedString, // destination buffer
    int nSize, // size of destination buffer
    string lpFileName // initialization file name 
    );string strFileName="FileName.ini";
    int intBufferSize=10;
    string strSec="Timer";
    string strK="Interval";
    string strReturn="";//There is somthing Wrong here 
    long lngRet=GetPrivateProfileString(strSec,strK,"",strReturn,intBufferSize,strFileName);//strResult=""; (strResult 期望值時 .ini文件中1000.) why ???ps:FileName.ini
    [Timer]
    Interval=1000
      

  2.   

    有现成的类,而且很好用的,我把过去自己写的程序当例子发给你
    public bool FileType(string FileName,string FileExt)
    {
        FileInfo TheFile=new FileInfo(FileName);
        try 
       {
            if(TheFile.Extension=="."+FileExt.Trim() || TheFile.Extension=="."+FileExt.ToUpper() ) 
           {
               TheFile=null;
               return true;
           }
           else
           {
            throw new FileTypeException("文件类型不是" + FileExt.ToString() );   
           }
        } 
        catch(FileTypeException e)
        {
    MessageBox.Show(e.Message,"提示" );
    TheFile=null;
    return false;
        }}
    public bool FindFile(string FilePath)
    {
        FileInfo TheFile=new FileInfo(FilePath);
        try 
       {
    if(TheFile.Exists) 
    {
        TheFile=null;
        return true;
    }
    else
    {
        throw new FileNotFoundException("文件未找到");  
    }
        } 
        catch(FileNotFoundException e)
        {
    MessageBox.Show(e.Message,"提示" );
    TheFile=null;
    return false;
        }
    }
    虽然不是直接打开,但用FileInfo类一定是可以读取文件内容的(一般都是stream一起使用的)绝对可以。
      

  3.   

    有现成的类,而且很好用的,我把过去自己写的程序当例子发给你
    public bool FileType(string FileName,string FileExt)
    {
        FileInfo TheFile=new FileInfo(FileName);
        try 
       {
            if(TheFile.Extension=="."+FileExt.Trim() || TheFile.Extension=="."+FileExt.ToUpper() ) 
           {
               TheFile=null;
               return true;
           }
           else
           {
            throw new FileTypeException("文件类型不是" + FileExt.ToString() );   
           }
        } 
        catch(FileTypeException e)
        {
    MessageBox.Show(e.Message,"提示" );
    TheFile=null;
    return false;
        }}
    public bool FindFile(string FilePath)
    {
        FileInfo TheFile=new FileInfo(FilePath);
        try 
       {
    if(TheFile.Exists) 
    {
        TheFile=null;
        return true;
    }
    else
    {
        throw new FileNotFoundException("文件未找到");  
    }
        } 
        catch(FileNotFoundException e)
        {
    MessageBox.Show(e.Message,"提示" );
    TheFile=null;
    return false;
        }
    }
    虽然不是直接打开,但用FileInfo类一定是可以读取文件内容的(一般都是stream一起使用的)绝对可以。