我有一份文字档案:
问题1:问题的内容及答覆A:答覆B:答覆C:答覆D:
我想读这个文件,并将数据插入我的数据库,如question1将进入问题列,而相应的应答将在应答列中.
string strPath = Server.MapPath("~/Test.doc");
// Request.PhysicalApplicationPath + "\\Test.doc";
FileStream fStream = new FileStream (strPath, FileMode.Open, FileAccess.Read);
StreamReader sReader = new StreamReader(fStream);
//TextBox2.Text = sReader.ReadToEnd();
string data1 = sReader.ReadToEnd();
sReader.Close();
Response.Write(data1);发布于 2013-02-13 07:11:14
试试像这样的东西
string strPath = Server.MapPath("~/Test.doc");
using (FileStream fs = new FileStream(strPath, FileMode.Open))
{
using (StreamReader reader = new StreamReader(fs, Encoding.UTF8))
{
string line = null;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
if (line.Contains("question"))
{
//read content here
}
}
}
}https://stackoverflow.com/questions/14847809
复制相似问题