[我的配置]
路径=E:\
0=文件1
1=文件2
2=文件3
3=文件4以上是我的INI配置文件 0-3后续可能还会有属于增长型
我想实现 插入一个 0=文件0
变为
[我的配置]
路径=E:\
0=文件0
1=文件1
2=文件2
3=文件3
4=文件4
应该怎么写

解决方案 »

  1.   

    需要全重写才行,ini重写即修改。既然你操作ini文件,那么IniFile类应该是有的
    IniFile infile = new IniFile("路径\\配置文件.ini");
    infile.WriteIni("我的配置", "0",文件0);
    infile.WriteIni("我的配置", "1",文件1);
      

  2.   

    可以把文件0~文件n保存到数组,然后按顺序写入ini文件。
      

  3.   

    一个INI的操作类    public class INI
        {
            // 声明INI文件的写操作函数 WritePrivateProfileString()
            [System.Runtime.InteropServices.DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
            // 声明INI文件的读操作函数 GetPrivateProfileString()
            [System.Runtime.InteropServices.DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);
            private string iniPath = null;
            public INI(string path)
            {
                this.iniPath = path;
            }        public void SetValue(string section, string key, string value)
            {
                WritePrivateProfileString(section, key, value, iniPath);
            }
            public string GetValue(string section, string key)
            {
                // 每次从ini中读取多少字节
                System.Text.StringBuilder sb = new System.Text.StringBuilder(255);
                // section=配置节,key=键名,temp=上面,path=路径
                GetPrivateProfileString(section, key, "", sb, 255, iniPath);
                return sb.ToString();
            }
        }之后就是 
    INI ini = new INI(your ini file path);
    ini.SetValue("我的配置", "0","文件0");
    ini.SetValue("我的配置", "1","文件1");
    ...
    这样就行了
      

  4.   

    写值的时候用
    WritePrivateProfileString
    读值的时候用
    GetPrivateProfileString