TOC default text changes color when "Update Field" is clicked

Connor Shore 50 Reputation points
2025-04-04T22:23:29.7966667+00:00

I have a question why the color changes in a specific document when "Update Field" is clicked. Our application creates output from a template. In the download link is the template file (TocUpdateIssueTemplate.docx) and the output generated from that template (TocUpdateIssueOutput_BeforeUpdate.docx). The output visually looks identical to the template as you can see. However, if you go to the line "No table of figures entries found" and right click on it and select "Update Fields" you will notice the text changes from blue to black. The resulting docx is TocUpdateIssueOutput_AfterUpdate.docx). The ooxml of the before and after document look pretty much identical except the <w:color> element has been removed in document.xml. The weird thing is, if you do "Update Fields" in the template document, the text remains the same color and the <w:color> element is not removed in the ooxml. Is there something in the output documents that cause this to happen when update is clicked or is this a weird one off issue? Any help is appreciated. Thank you!

Link to files: https://windwardstudios.box.com/s/aly9emyf1bpoz6yf5y6961c3f08zrpqp

Let me know if you need any clarification or have any issues with the files.

Connor

Office Open Specifications
Office Open Specifications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Open Specifications: Technical documents for protocols, computer languages, standards support, and data portability. The goal with Open Specifications is to help developers open new opportunities to interoperate with Windows, SQL, Office, and SharePoint.
146 questions
{count} vote

2 answers

Sort by: Most helpful
  1. mkaszewiak 5 Reputation points Microsoft Employee
    2025-04-08T12:40:54.8566667+00:00

    Hi @Connor Shore I investigated files you have shared and it looks to me that issue was caused at the code level when file(TocUpdateIssueBeforeUpdate) was generated from the template you have provided.

    When I used this simple code to generate file from your template issue doesn't occur. Could you please test it on your site and let me know how it works for you.

    string templatePath = @"C:\source\TestFiles\TocUpdateIssueTemplate.docx";
    
            string outputPath = @"C:\source\TestFiles\DocFromTemplate.docx";
    
            MemoryStream memoryStream;
    
            using (memoryStream = new MemoryStream())
    
            {
    
                using (WordprocessingDocument generatedDoc = WordprocessingDocument.CreateFromTemplate(templatePath, false))
    
                {
    
                    MainDocumentPart? mainDocumentPart = generatedDoc.MainDocumentPart;`
    
                    generatedDoc.Clone(memoryStream);`
    
                    File.WriteAllBytes(outputPath, memoryStream.ToArray());
    
                }
    
            }
    

    Best regards,

    Mariusz Kaszewiak


  2. mkaszewiak 5 Reputation points Microsoft Employee
    2025-04-09T08:47:30.0166667+00:00

    Hi @Conor Shore Thank you for the clarification. I am currently investigating the issue and will update you as soon as I have some findings.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.