(一)inifile.cs
using system;
using system.runtime.interopservices;
using system.text;
namespace createwebdir
{
/// <summary>
/// inifile 的摘要说明。
/// </summary>
public class inifile
{
public string path;
public inifile(string inipath)
{
path = inipath;
}
[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 void iniwritevalue(string section,string key,string value)
{
writeprivateprofilestring(section,key,value,this.path);
}
public string inireadvalue(string section,string key)
{
stringbuilder temp = new stringbuilder(255);
int i = getprivateprofilestring(section,key,"",temp, 255, this.path);
return temp.tostring();
}
}
}
=======================================================
(二)使用示例
string inifile = @"d:/bug2000.ini";
if (!file.exists(inifile))
{
using (filestream fs = file.create(inifile))
{
fs.close();
}
}
inifile myini = new inifile(inifile);
for(i=0;i<args.length;i++)
{
myini.iniwritevalue("webdir","arg"+i.tostring(),args[i]);
}
注册会员,创建你的web开发资料库,