Extract / pull TOC after Updating it?

Hi,

Couple questions for you please.

  1. Do I need to remove all references to entryRefCode? Including the bit of code in TableOfContentsToDataTable() where it is selected?
if (isHyperlinked)
{
    // Collect all runs in the field code until we encounter the field separator
    while (currentNode.NodeType != NodeType.FieldSeparator)
    {
        entryRefCode.Append(currentNode.ToTxt().Trim());
        currentNode = currentNode.NextPreOrder(doc);
    }
    // Skip past field separator
    currentNode = currentNode.NextPreOrder(doc);
}
  1. Do I also need to include:
table.Rows.Add(new object[]
 { entryRefCode.ToString(), entryText.ToString(), entryPositionNode,
 fieldResultRuns, pageRefCode.ToString(), pageText.ToString() });

at the second table.Rows.Add just after the comment "Add to datatable? (About 36 lines lower than the first.)

  1. When I run with the modified code, I get two instances of each item in the datatable. One with and one with out pageRefCode and pageText columns populated. Do you get the same? This results in an error, the the debugger complains that the cells can not be empty/null.

Thanks!

-Rob

Hi Rob,
Thanks for your inquiry.
Apart from the one I described in my last post, I don’t think it is nessary to remove them. However since they are no longer used you can feel free to remove them though. You should remove the one relating to the Replace method as this may somehow have an affect for some TOC.
Regarding your other queries, I think it may be easier if I just attach the full code here. This code is working on my side. You can find it attached to this post.
If you have any further queries, please feel free to ask.
Thanks,

Thanks for posting the code. There were a couple of other difference that I hadn’t taken into account when I modified the code on my side. Once I cut and pasted your code into the relevant functions, it works like a champ.

Thanks.

Hi,

Is there a way to move around the correct heading styles, too. For example, I change my above code to have InsertTableOfContents("\o “3-3” \h \z \t “Heading 4,1"”). When I run the code the color and strike through follow the text correctly. However, the font sizes associated with the different heading styles does not follow, but stays in the original entry spot. Any ideas?

Thanks.

Hi Rob,
Thanks for your inquiry.
Sure, this only takes a few extra lines per method. To avoid any confusion I will repost the full code with the changes already made.
Also on another look I think you will need to keep the EntryText field so you can easily retrieve the text of the TOC entry.
Thanks,

Yep, you are right. Just a few more lines of code. I thik I could of figured it ou, eventually, but you made it so much simpler and quicker. Thank you very much. I just had to do a quick difference comparison on the files, copied over the additions, and was good to go.

Thanks.