Ms word 如何在asp.NETC中读取word文档#

Ms word 如何在asp.NETC中读取word文档#,ms-word,document,Ms Word,Document,我正在asp.NETC#3.5Windows应用程序中做一个项目,需要阅读word文档。我想知道如何逐字读取*.doc文件。。。。我怎么做?Microsoft.Office.Interop.Word.Application WApp; Microsoft.Office.Interop.Word.Document Wdoc WApp = new Microsoft.Office.Interop.Word.Application(); //Opening Word file Thread.Sleep

我正在asp.NETC#3.5Windows应用程序中做一个项目,需要阅读word文档。我想知道如何逐字读取*.doc文件。。。。我怎么做?

Microsoft.Office.Interop.Word.Application WApp; Microsoft.Office.Interop.Word.Document Wdoc

WApp = new Microsoft.Office.Interop.Word.Application();
//Opening Word file
Thread.Sleep(5312);
Wdoc = WApp.Documents.Open(@"C:\Users\Doc.doc");
object start = 0;
object end = Wdoc.Characters.Count;
Range rng = Wdoc.Range(ref start, ref end);


int wordCount = Wdoc.Words.Count;
// Display retrieved (incomplete) text
rng.TextRetrievalMode.IncludeHiddenText = false;
rng.TextRetrievalMode.IncludeFieldCodes = false;

// Find phrase in text string
string WTest;
string[] Title;
Title = new string[10];
Title[1] = "word1 ";
Title[2] = "word2 ";
Title[3] = "word3 ";
Title[4] = "word4 ";
Title[5] = "word5 ";
Title[6] = "word6 ";
Title[7] = "word7 ";
Title[8] = "word8 ";
Title[9] = "word9 ";
int icount = 1;
int n = 1;
int i=1;

while (icount <= wordCount)
{
    WTest = Wdoc.Words[icount].Text.ToString();

    foreach(string element in Title)
    {

        if (Title[i] == WTest)
        {
            Assert.IsTrue(true);
            icount++;
            i++;
            break;
        }
        else if (i == wordCount)
        {
            Assert.Fail("Doc has no Data");
            break;
        }
        else
        {
            icount++;


        }
        break;  
    }

    continue;
}
 Wdoc.Close(true);
 WApp.Quit();
WApp=new Microsoft.Office.Interop.Word.Application();
//打开Word文件
睡眠(5312);
Wdoc=WApp.Documents.Open(@“C:\Users\Doc.Doc”);
对象开始=0;
对象结束=Wdoc.Characters.Count;
范围rng=Wdoc.范围(参考起点、参考终点);
int wordCount=Wdoc.Words.Count;
//显示检索到的(不完整)文本
rng.textrerievalmode.IncludeHiddenText=false;
rng.TextRetrievalMode.IncludeFieldCodes=false;
//在文本字符串中查找短语
字符串测试;
字符串[]标题;
Title=新字符串[10];
标题[1]=“字1”;
标题[2]=“单词2”;
标题[3]=“word3”;
标题[4]=“字4”;
标题[5]=“word5”;
标题[6]=“word6”;
标题[7]=“字7”;
标题[8]=“word8”;
标题[9]=“word9”;
int-icount=1;
int n=1;
int i=1;

首先,你可以告诉我们你的平台、语言等。你能进一步解释一下这个解决方案吗?