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和本应用程序在同一个目录里?
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和本应用程序在同一个目录里?
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();
} }}
OpenFileDialog ofd=new OpenFileDialog();
ofd.RestoreDirectory=true;
具体请查阅MSDN
万分感谢..System.Windows.Forms.Application.StartupPath;
这个乜可以获得程序运行的路径..学到不少东西
结贴....