Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:13:46+00:00 2026-06-15T08:13:46+00:00

I have a docx Word document that contains Content Controls bound to data in

  • 0

I have a docx Word document that contains Content Controls bound to data in a CustomXMLPart.

This document (or bookmarks therein) is then included in another Word document by using INCLUDETEXT.

When the first document is included into the second is there any way of getting the CustomXMLPart from the original document (I already have a VSTO Word Addin running in Word looking at the document)?

What I want to do is merge it with the CustomXMLParts already present in the second document so that the Content Controls are still bound to the data in the XMLPart.

Alternatively, is there another way to do this without using the INCLUDETEXT field?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:13:47+00:00Added an answer on June 15, 2026 at 8:13 am

    I decided this probably wasn’t possible using VSTO and IncludeText fields and investigated using altChunks as an alternative.

    I was already doing some processing on the file using the Open XML SDK 2 before opening it so could so the extra work required to merge the document together there.

    Although using the altChunk method embeds the whole second document in the first, including its own CustomXmlParts, the CustomXmlParts are discarded by Word when the document is opened and the second merged with the first.

    I ended up with code similar to the following. It replaces defined Content Controls with altChunk data and merges specific CustomXmlParts together.

        private static void CreateAltChunksInWordDocument(WordprocessingDocument doc, string externalDocumentPath)
        {
            foreach (var control in doc.ContentControls().ToList()) //Have to do .ToList() on this as when we update the Doc in the loop it stops enumerating otherwise
            {
                SdtProperties props = control.Elements<SdtProperties>().FirstOrDefault();
                if (props == null)
                    continue;
    
                SdtAlias alias = props.Elements<SdtAlias>().FirstOrDefault();
                if (alias == null || !alias.Val.HasValue || alias.Val.Value != "External Template")
                    continue;
    
                using (WordprocessingDocument externaldoc = WordprocessingDocument.Open(externalDocumentPath, false))
                {
                    //Replace the Content Control with an AltChunk section, and stream in the external file
                    string altChunkId = "AltChunkId" + Guid.NewGuid().ToString().Replace("{", "").Replace("}", "").Replace("-", "");
    
                    AlternativeFormatImportPart chunk = doc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);
                    chunk.FeedData(File.OpenRead(externalDocumentPath));
    
                    AltChunk altChunk = new AltChunk();
                    altChunk.Id = altChunkId;
    
                    OpenXmlElement parent = control.Parent;
                    parent.InsertAfter(altChunk, control);
                    control.Remove();
    
                    XDocument xDocMain;
                    CustomXmlPart partMain = MyCommon.GetMyXmlPart(doc.MainDocumentPart, out xDocMain);
    
                    XDocument xDocExternal;
                    CustomXmlPart partExternal = MyCommon.GetMyXmlPart(externaldoc.MainDocumentPart, out xDocExternal);
    
                    if (xDocMain != null && partMain != null && xDocExternal != null && partExternal != null)
                    {
                        MyCommon.MergeXmlPartFields(xDocMain, xDocExternal);
    
                        //Save the updated part
                        using (Stream outputStream = partMain.GetStream())
                        {
                            using (StreamWriter ts = new StreamWriter(outputStream))
                            {
                                ts.Write(xDocMain.ToString());
                            }
                        }
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So what I have is a MS Word docx file that contains some data
I have a word document (docx format) that I need to populate with data
I have a bit of code that will open a Word 2007 (docx) document
I have a word document in docx format with data in repeating format pattern.
I have this snippet of code that should open a docx file and I
I have extracted a number of OleObject files from a Word DOCX document (oleObject1.bin
I have a CSV document that is of the following structure Headers Path,Publish,Hashlist,Package Content
I have multiple <body> tags from an word document. I do this with the
I have an idea of converting Word document(.doc/.docx) files to Help file(.chm) format. I
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.