I am getting Word document page wise text and adding to list. But in my document I have EndNotes also that is not extraxting the text. Please help me.
public List GetEachPageText()
{
statusTotalNoRowsPanel.Text = "";
statusPanel.Text = "";
elapsedtimePanel.Text = "";
statusPanel.Text = "Starting...";
TimeElapsed_dispatcher.Tick += new EventHandler(dispatcherTimer_Tick);
TimeElapsed_dispatcher.Interval = new TimeSpan(0, 0, 0, 0, 100);
TimeElapsed_dispatcher.Start();
DoEvents();
UTCStartTime = DateTime.UtcNow;
//Store each page in a collection for extracting text
List Pages = new List();
Microsoft.Office.Interop.Word.Document Doc = Globals.ThisAddIn.Application.ActiveDocument;
try
{
// Get document object
object ReadOnly = false;
object Visible = false;
Doc.Application.ScreenUpdating = false;
object missing = System.Reflection.Missing.Value;
// Get pages count
Microsoft.Office.Interop.Word.WdStatistic PagesCountStat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
int TotalPages = Doc.ComputeStatistics(PagesCountStat, ref missing);
//Get pages
object What = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
object Which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute;
object Start;
object End;
int PageCtr = 1;
object CurrentPageIndex = PageCtr;
do
{
DoEvents();
Start = Doc.ActiveWindow.Selection.GoTo(ref What, ref Which, ref CurrentPageIndex, ref missing).Start;
if (PageCtr + 1 <= TotalPages)
{
CurrentPageIndex = PageCtr + 1;
End = Doc.ActiveWindow.Selection.GoTo(ref What, ref Which, ref CurrentPageIndex, ref missing).Start - 1;
}
else
{
End = Doc.Range(ref missing, ref missing).End - 1;
}
if (Convert.ToInt32(Start.ToString()) != Convert.ToInt32(End.ToString()) && Convert.ToInt32(Start.ToString()) < Convert.ToInt32(End.ToString()))
Pages.Add(Doc.Range(ref Start, ref End).Text.Trim());
else
Pages.Add(Doc.Range(ref Start).Text.Trim());
PageCtr++;
} while (PageCtr <= TotalPages);
object firstPage = 1;
Doc.ActiveWindow.Selection.GoTo(ref What, ref Which, ref firstPage, ref missing);
Doc.Application.ScreenUpdating = true;
}
catch (Exception ex)
{
throw ex;
}
return Pages;
}