解析word文档和数据库
问题描述:
插入我有一个word文件:解析word文档和数据库
问题1:有 回答问题的内容: 答案B: 答案C: 答案d:
我想读取这个文件,并在我的数据库 插入数据,例如问题1将在问题去柱和各自回答将在去接听列.........
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);
答
尝试这样的事情
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
}
}
}
}
你可以发布您的代码? – DON 2013-02-13 06:34:08
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); – vidyasagar2012 2013-02-13 07:01:03
但上述代码是没有用的,我不知道任何关于在C#中的文件解析... ....你可以帮我......在实现输出 – vidyasagar2012 2013-02-13 07:02:07