word document is like this
paragraph1:some text in this para
paragraph2: sometext in this para
big =large
center = middle
paragraph3: some text in this para
I want to get paragraph2 text from starting to ending(sometext........... center =middle) and I should insert this data into sql table using c#
can any body tell how to do this
thanq
Loading

Hemant SrivastavaRank #581 · 4.2K reputationPosted Sep 19, 2013, 6:05 AM EDT
public string ReadFileParaContainingWord(string path, string word)
{
int i = 0;
StringBuilder sb = new StringBuilder();
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
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;
// Count number of paragraphs in the file
long parCount = DocPar.Count;
// Step through the paragraphs
while (i < parCount)
{
i++;
if (DocPar[i].Range.Text.Contains(word))
{
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());
}
Hope it will work.
Hemant SrivastavaRank #581 · 4.2K reputationPosted Sep 17, 2013, 9:30 AM EDT
try this:
//To read paragraph contents of a Word document using Microsoft.Office.Interop.Word DLL
private void readFileContent(string path, int paraGraphNum)
{
int i = 0;
StringBuilder sb = new StringBuilder();
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
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;
// Count number of paragraphs in the file
long parCount = DocPar.Count;
// Step through the paragraphs
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);
Console.WriteLine(sb.ToString());
}
Hemant SrivastavaRank #581 · 4.2K reputationPosted Sep 18, 2013, 5:05 AM EDT
shahanaz v5 reputationPosted Sep 18, 2013, 9:01 PM EDT
i want to search specific string in whole document if it will be there in that documenent then it should get that paragraph
thanq
shahanaz v5 reputationPosted Sep 23, 2013, 4:46 AM EDT