StC Original TOC Template.docx (6.6 MB)
Hi
I am trying to inset TOC in the document at a pre defiend bookmark location everything works fine but the brackets “(” comes inverted. Once the document is opened in workd i right click the TOC and click updated fiel the brackets become proper . The way my code works , first check if there is an existing TOC in the document if yes it add bookmark in the document in TOC location and removes the TOC. Once some other processes are done new TOC is inseted in the place of bookmark and the bookmark is removed.
Please see the screenshot of the problem below.
The code used to inset TOC is below
public void AddTableOfContents(ref Document doc, ArrayList TocFormatCodes)
{
List<Bookmark> bookmarks = doc.Range.Bookmarks.Where(b => b.Name.StartsWith("BM_TOC")).ToList();
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < bookmarks.Count; i++)
{
string tocFormatSwitches = "\\o \"1-3\" \\h \\z \\u";
Bookmark bm = bookmarks[i];
try
{
tocFormatSwitches = (string)TocFormatCodes[i];
}
catch (Exception)
{
}
builder.ParagraphFormat.Bidi = true;
builder.MoveToBookmark(bm.Name);
Field toc = builder.InsertTableOfContents(tocFormatSwitches);
toc.Update();
bm.Remove();
}
}
Please find the attached input and output document
out-rountrip.docx (6.4 MB)