Share via

Word.ContentControl.insertFileFromBase64 does not replace Date Picker Content Controls in document headers.

Samardeep Mahur 40 Reputation points
2026-04-06T09:50:09.2066667+00:00

Product: Office.js Word Add-in (Word on the Web / Word Desktop)
API used: Word.ContentControl.insertFileFromBase64() / Word.Range.insertFileFromBase64()**
Scenario:**

I am building a Word Web Add-in that programmatically replaces document content using the insertFileFromBase64 API. The workflow is:

  1. The original document (currently open in Word) contains Content Controls, including a Date Picker Content Control placed in the document header.
  2. new document (base64-encoded .docx) is generated server-side. In this new document, the field that was originally a Date Picker Content Control is now represented as a Plain Text Content Control.
  3. We call insertFileFromBase64 to replace the body content of the original document with the new document's content.

Problem:

issue occur after insertFileFromBase64 completes:

  1. Date Picker Content Control is not replaced in the document header: The original Date Picker Content Control in the document is not replaced or updated by the corresponding Plain Text Content Control from the new base64 document. The Date Picker Content Control persists unchanged even though the new document contains a Plain Text Content Control with the same tag/title at the same position.

Code


await Word.run(async (context) => {
    const body = context.document.body;
    body.insertFileFromBase64(base64String, Word.InsertLocation.replace);
    await context.sync();
});
Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments

Answer accepted by question author
  1. Michelle-N 15,135 Reputation points Microsoft External Staff Moderator
    2026-04-06T10:44:05.26+00:00

    Hi @Samardeep Mahur

    From the information you provided, I understand that after insertFileFromBase64 completes, the Date Picker Content Control in the document header is not replaced.

    After researching, it seems that currently the insertFileFromBase64 API in Office.js only replaces the body of the document, excluding the header, footer, or other parts of the document. That is also why the Date Picker Content Control (located in the header) remains the same as in the original document, even though your server-generated base64 file contains a Plain Text Content Control at the same position / same tag / same title.

    When called on the body, insertFileFromBase64 maps directly to the body story of the document. In the OOXML structure, the header and footer are separate "stories". The API simply does not touch these stories, so the original Date Picker Content Control in the header remains intact.

    Therefore, in this case, please refer to the new document-level API method (requires Word API 1.5), specifically Document.insertFileFromBase64:

    await Word.run(async (context) => {
        // Replace the entire document (body + headers + footers + sections)
        context.document.insertFileFromBase64(
            base64String,
            Word.InsertLocation.replace,
            {
                // Optional but recommended – control what gets imported
                importStyles: true,
                importTheme: true,
                importDifferentOddEvenPages: true,   // if your header/footer uses this
                // importPageSetup: true,            // if you need margins/orientation etc.
            }
        );
     
        await context.sync();
    });
    

    In addition, please refer the following documents:

    Troubleshoot Word add-ins
    Word.Document class

    I hope the information I found helps clarify your scenario. Let me know if you need further details.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".   

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Answer accepted by question author
  1. Q&A Assist
    2026-04-06T09:50:28.1233333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Word.ContentControl.insertFileFromBase64 and Range.insertFileFromBase64 only insert/replace content within the scope of the target object (a content control or a range/body). They do not affect header/footer content controls unless the insertion target is explicitly within the header/footer.

    In the provided code, the call is made on context.document.body:

    const body = context.document.body;
    body.insertFileFromBase64(base64String, Word.InsertLocation.replace);
    

    This replaces only the main document body with the content from the Base64 document. Headers, footers, and their content controls (including the Date Picker Content Control in the header) are not touched, so the original Date Picker Content Control in the header remains unchanged.

    To replace or update header content controls, the insertion must be performed against the header range or section(s), not the document body. The Document.insertFileFromBase64 overload can copy headers/footers from the source document into the destination document when used at the document level, but ContentControl.insertFileFromBase64 and Range.insertFileFromBase64 do not automatically propagate changes into headers.

    Additionally, note that insertFileFromBase64 has documented limitations (for example, it does not support documents containing ActiveX controls), and it operates on the content of the target object only.


    References:

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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