openFileDialog1.FileName = "fineplus.ini";
                openFileDialog1.Filter = "INI files (*.ini)|*.ini";
                openFileDialog1.ShowDialog();
                ini = openFileDialog1.FileName;
                IniFile foolme = new IniFile(".//FoolMeShell.ini");
                foolme.IniWriteValue("FFineShell", "fineplus",ini);
openfiledialog选择文件之后ini=d:\cc\fineplus.ini
创建FooleMeShell.ini文件就会在d:\cc\文件目录里.为什么?.//FoolMeShell.ini不是指的本应用程序的路径么?
如果直接写成IniFile foolme = new IniFile("FoolMeShell.ini");
FooleMeShell.ini文件就会在系统windows里创建..
如何才能让创建的FooLMeShell.ini和本应用程序在同一个目录里?

解决方案 »

  1.   

    请问楼主 IniFile 是个什么类? 是楼主自己定义的类?
      

  2.   

    IniFile 是读写ini文件的类..
    using System;
    using System.Runtime.InteropServices;
    using System.Text;namespace 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(ss, 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(ss, Key, "", temp,255, this.path);
                return temp.ToString();
            }    }}
      

  3.   

    OpenFileDialog 类在选取了一个文件后,会把当前目录设为此文件所在的目录,如果你需要在选择完成后还原当前目录,请使用RestoreDirectory,如下:
    OpenFileDialog ofd=new OpenFileDialog();
    ofd.RestoreDirectory=true;
    具体请查阅MSDN
      

  4.   

    谢谢告诉我这个很好的方法..学习了..
    万分感谢..System.Windows.Forms.Application.StartupPath;
    这个乜可以获得程序运行的路径..学到不少东西
    结贴....