asp.net读取文本文件并加入DataTable中

string configfile = Server.MapPath("~/csspath.txt");

string lineStr = null;

DataTable dt = new DataTable();

dt.Columns.Add("loc");

if(File.Exists(configfile))

{ StreamReader re = File.OpenText(configfile);

  try{   while((lineStr = re.ReadLine()) != null)  

 {    DataRow dr = dt.NewRow();    dr["loc"] = lineStr;

   dt.Rows.Add(dr);   }

}

finally {   re.Close(); }

}

posted @ 2011-07-15 17:06  你妹的sb  阅读(377)  评论(0编辑  收藏  举报
百度一下