读文件:
//查找文件是否存在
if (!File.Exists(strFile))
return;
//流文件
StreamReader sr = new StreamReader(strFile);
try
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
//判断配置类型,并赋值:
//服务器
if(line.IndexOf("data source=") != -1)
this.FWQ = line.Substring(line.IndexOf("=")+1); }
catch (Exception e)
{
// Let the user know what went wrong.
MessageBox.Show("The file could not be read:"+e.Message);
}
try
{
sr.WriteLine ("data source=" + this.FWQ);
sr.WriteLine ("Connect Timeout=30");
sr.Close();
}
catch (Exception e)
{
// Let the user know what went wrong.
MessageBox.Show("The file could not be writed:"+e.Message);
}