I need to identity a part of word document with a key then in need to copy it into another word document. how can i achieve it through C#.net.
i tried the following it result as text i need it as document
and paragraph should be i identified with a key word
What I have tried:
public string ReadFileContent(string path, int paraGraphNum)
{
int i = 0;
StringBuilder sb = new StringBuilder();
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open
(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
Microsoft.Office.Interop.Word.Paragraphs DocPar = doc.Paragraphs;
long parCount = DocPar.Count;
while (i < parCount)
{
i++;
if (i == paraGraphNum)
{
sb.Append(DocPar[i].Range.Text);
break;
}
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
return (sb.ToString());
}
}