/*建立一个Windows应用程序,上面添加一个按纽,单击事件为button1_Click*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace _01
{
public partial class Form1 : Form
{ [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);
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e) //一个按纽事件
{
string name = openfile();
if (name != "")
{
MessageBox.Show(name);
long s = WritePrivateProfileString("a", "key1", name, "./config.ini"); //这样将不会写入INI文件
} } private string openfile()
{
OpenFileDialog temp = new OpenFileDialog();
if (temp.ShowDialog() == DialogResult.OK)
return temp.FileName;
else return "";
}
}
}下午搞到现在才找出的问题,大家有没有这样的问题帮我试试,上面的代码如果是在VS2005中按F5运行,不会创建INI文件,如果到Debug目录下运行这个exe文件,就会创建ini文件,搞得头都大了。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace _01
{
public partial class Form1 : Form
{ [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);
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e) //一个按纽事件
{
string name = openfile();
if (name != "")
{
MessageBox.Show(name);
long s = WritePrivateProfileString("a", "key1", name, "./config.ini"); //这样将不会写入INI文件
} } private string openfile()
{
OpenFileDialog temp = new OpenFileDialog();
if (temp.ShowDialog() == DialogResult.OK)
return temp.FileName;
else return "";
}
}
}下午搞到现在才找出的问题,大家有没有这样的问题帮我试试,上面的代码如果是在VS2005中按F5运行,不会创建INI文件,如果到Debug目录下运行这个exe文件,就会创建ini文件,搞得头都大了。
解决方案 »
- 用MySqlDataReader对象读取数据库的时间对象
- )在NET中,.NET Framework由()组成.(选择一项) 检举 | 2008-10-21 20:10 提问者: wangyuteng | 浏览次数:1
- c#界面跳转问题
- 请问我一个线程可以导 x 条数据,总共有 M 条数据,怎么计算我需要开几个线程?
- 关于C#中绘制K线图的问题??
- C#调用matlab,搞不定啊,请诊断
- 请问各位大侠(关于通过Modem如何上传文件?)
- 请问怎样实现winform窗口的切换?
- 有关.net library的继承?
- 一个ADO.NET的问题
- 求实例化委托时,传入的方法具体是什么类型的参数?
- 金碟KIS的主界面是怎样实现的
调试结束后它删除了这个文件正常
是这个文件路经问题 ./config.ini
不是没有创建,而是把这个文件写到了别的地方去了,如果想创建自己目录下的,不能用./config.ini,应该用 System.IO.Directory.GetCurrentDirectory() ,因为用模拟对话框打开后会把 ./ 的引用重写的。