string Filename=this.MapPath(this.TemplateSourceDirectory)+"\\config\\RegisterAgent.ini";
FileStream fs =new FileStream(Filename,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
while(sr.Peek()>-1)
{
this.ListBoxRegAgent.Items.Add(sr.ReadLine());
}
FileStream fs =new FileStream(Filename,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
while(sr.Peek()>-1)
{
this.ListBoxRegAgent.Items.Add(sr.ReadLine());
}
//==读写Ini文件的类======================================
public class IniFile
{
//文件INI名称
private string FileName;
////声明读写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 IniFile(string inipath)
{
// TODO: Add constructor logic here
FileName = inipath;
} //写INI文件
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.FileName);
} //读取INI文件指定
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.FileName);
return temp.ToString();
}
}
public static extern int GetPrivateProfileInt(string SubConfig,string varStr,int defvalure,string filepath);
[DllImport("kernel32.dll",EntryPoint = "GetPrivateProfileString")]
public static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);