第一:你可以笨一点,ini也就是txt文件。
       你用File.CreateText可以创建ini文件,就是改改扩展名而已
       然后你用StreamReader,StreamWriter进行操作
 第二:如果你不想用这个,可以调用api函数。
 肯定有更好的办法,关注中

解决方案 »

  1.   

    api啊,这里有很多关于ini的答案,你搜索一下
      

  2.   

    GetModuleFileName(  );
    GetPrivateProfileString();
      

  3.   

    using System;
    using System.Runtime.InteropServices;
    using System.Text;namespace Hillfree.Configurations.Ini
    {
        /// <summary>
        /// Create a New INI file to store or load data
        /// </summary>
        public class IniFile
        {
            public string path;        [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);        /// <summary>
            /// INIFile Constructor.
            /// </summary>
            /// <PARAM name="INIPath"></PARAM>
            public IniFile(string INIPath)
            {
                path = INIPath;
            }
            /// <summary>
            /// Write Data to the INI File
            /// </summary>
            /// <PARAM name="Section"></PARAM>
            /// Section name
            /// <PARAM name="Key"></PARAM>
            /// Key Name
            /// <PARAM name="Value"></PARAM>
            /// Value Name
            public void IniWriteValue(string Section,string Key,string Value)
            {
                WritePrivateProfileString(Section,Key,Value,this.path);
            }
            
            /// <summary>
            /// Read Data Value From the Ini File
            /// </summary>
            /// <PARAM name="Section"></PARAM>
            /// <PARAM name="Key"></PARAM>
            /// <PARAM name="Path"></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();
            }  public string IniReadValue(string Section, string Key, string DefaultValue, bool bMustHave)
      {
       StringBuilder temp = new StringBuilder(255);
       int i = GetPrivateProfileString(Section,Key,"",temp, 
        255, this.path);   if (i == 0)
       {
        if(bMustHave)
        {
         this.IniWriteValue(Section, Key, DefaultValue);
        }
        return DefaultValue;
       }   return temp.ToString();
      }
        }
    }
      

  4.   

    这是在Net Framework 1.0里面的一个读写ini的类,现在应该还是管用的。不过如果没有特别的要求,建议想xml的配置文件过渡。在《程序员增刊》里面有一篇文章详细的介绍了ini到xml配置文件的转换方法。同时还有一个即可读ini,也可以读xml配置文件的类IniReader。如果你找不到,我可以发给你。此外,.net框架同样有配置文件的框架,如果仅仅需要存储某些配置信息。可以利用。也就是yourfile.exe.config的读取。ConfigurationSettings 参见。
      

  5.   

    是的,INI文件是文本文件,由若干节(section)组成,在每个带括号的标题下面,是若干个关键词(key)及其对应的值(Value)
     在VC中提供了API函数进行INI文件的读写操作,可C#编程语言中却没有相应的方法。请问大家有没有更更好的方法。 我的意思是能正确的显示.INI的内容,不能有乱码出现。而且最好以树性显示。
      

  6.   

    显示层是显示层的事情,读文件是读文件的事情。上面那段代码是C#的。肯定可以读写INI。不过看到你的需求,感觉就用文件读写就行了。用不找什么更多的东东。