纯手写代码 非copy
下面有测试连接 在我自己的服务器上...有时候服务器会出问题.....
代码:
http://help.kansea.com/zhidao/csharp/298037741.html调用方法
myini = new _Ini("ini文件地址");
myini.IniWriteValue("Main","01.exe");
string str = myini.IniReadValue(InstallDir);
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace KanSea.XBATools
{
class _Ini
{
public string path; //INI文件名
public _Ini(string inipath)
{
//this.path = System.Environment.CurrentDirectory + "\\KanSea_XBA.ini";
this.path = inipath;
}
//声明读写INI文件的API函数
[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);
//写INI文件
public void IniWriteValue(string Key, string Value)
{
WritePrivateProfileString("中括号字符 MyApp01 ", Key, Value, this.path);
}
//读取INI文件指定
public string IniReadValue(string Key)
{
try
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString("MyApp01", Key, "", temp, 255, this.path);
return temp.ToString().Trim();
}
catch { return null; }
}
}
}
追问我试过这种方法,结果是:
iniFile.ini
文件大小:0字节
追答我一直都用这个源码.....怎么会出错
我的程序http://help.kansea.com/zhidao/csharp/298037741.7z
追问您访问的页面已删除或不存在
追答你说你试过 是试过我的代码么 我觉得不是
还有 上面说过 "下面有测试连接 在我自己的服务器上...有时候服务器会出问题....."
你试试看
代码方面 你要适当修改一下
"中括号字符 MyApp01 "和"MyApp01" 换成你自己的 或者设成用变量传
我的程序的截图