Hi Nitin,
Thanks for your inquiry. In your case, I suggest you please insert a bookmark at the end of document and add it into toc array list as shown below. Hope this helps you. Please let us know if you have any more queries.
Document doc = new Document(WordFilePath);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.StartBookmark("_TocEnd");
builder.EndBookmark("_TocEnd");
//***********************************************************
// GET CONTENT
// **********************************************************
NodeCollection nodes = doc.GetChildNodes(NodeType.FieldStart, true);
// Get list of bookmarks listed in TOC
ArrayList tocitems = new ArrayList();
foreach (Aspose.Words.Fields.FieldStart fstart in nodes)
{
if (fstart.FieldType == Aspose.Words.Fields.FieldType.FieldPageRef)
{
String fieldText = GetFieldCode(fstart);
if (fieldText.Contains("_Toc"))
{
fieldText = fieldText.Substring(fieldText.IndexOf("_Toc"), fieldText.Length - fieldText.IndexOf("_Toc")).Replace("\\h", "").Trim();
tocitems.Add(fieldText);
}
}
}
tocitems.Add("_TocEnd");
LBL_TOTAL_TOC_ITEMS.Text = tocitems.Count.ToString();
// **************************************************