0
Answer

getting page number when reading file by paragraphs

Vit Vomacko

Vit Vomacko

14y
4.2k
1
Hi, I have a small "program", which is ment to read MS word file line by line (actually by paragprahs), I managed to find some examples, so I made it work. But I adittionaly need to know, when I am going to next page (i will make statistics of paragraphs per page basics). Getting the number of page is problem for me: here is the function which do the reading:
     private void spust_Click(object sender, RoutedEventArgs e)
{
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
// File Path
string strFilePath = "C:/TestRead.doc";
// Create obj filename to pass it as paremeter in open
object objFile = strFilePath;object objNull = System.Reflection.Missing.Value;
object objReadOnly = true;
//Open Document
Microsoft.Office.Interop.Word.Document Doc = wordApp.Documents.Open(ref objFile, ref objNull, ref objReadOnly, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull);

// To read each line consider each line as paragraph Docuemnt
int i = 1;
foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph in Doc.Paragraphs)
{
try {lblName.Content += Doc.Paragraphs[i].Range.Text;
#########
--> CurrentPage = Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage; //CurrentPage contains current page number
#########
}catch (Exception ex){throw ex;}i++;
}
// close document and Quit Word Application
Doc.Close(ref objNull, ref objNull, ref objNull);
wordApp.Quit(ref objNull, ref objNull, ref objNull);
}

It would be perfect if you can suggest me how to get page number.

Thanks a lot!