We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

[DOCX] InsertDocx2docx Break section not visible in result


When I make a conversion for replace a tag in a Docx to another Docx. Section Break, break page are not keep in resultat.

Could you give me an advice for keep break in result docx?

Code :

public void InsertDocx2docxTest()

List filesToInsert = new List();
List insertTags = new List();
Document d1= new Document(@“D:\Temp\test insertdocx2docx\WORD_1.docx”);
Document d0 = new Document(@“D:\Temp\test insertdocx2docx\WORD_2.docx”);
MemoryStream m1 = new MemoryStream();


d0.Save(@“D:\Temp\test insertdocx2docx\WORD_2_res.docx”);
d1.Save(@“D:\Temp\test insertdocx2docx\WORD_1_res.docx”);
//Search all tag in order to insert the doc at the right place
NodeCollection allSections = d0.GetChildNodes(NodeType.Section, true);
List nodeToDelete = new List();
int iLoop = 0, nbTag = 0;
StringBuilder errorTags = new StringBuilder();
errorTags.AppendLine(“Tag(s) Unknow :”);

Dictionary<String, MemoryStream> dico = new Dictionary<String, MemoryStream>();

foreach (String tag in insertTags)
dico.Add(tag, filesToInsert[iLoop]);

DocumentBuilder builder = new DocumentBuilder(d0);
foreach (KeyValuePair<String, MemoryStream> pair in dico)
if (d0.GetText().IndexOf(pair.Key) >= 0)
FindAndInsertDocument replacedoc = new FindAndInsertDocument(pair.Value);
d0.Range.Replace(new Regex(pair.Key), replacedoc, false);
if (!replacedoc.Replaced)
foreach (Field field in d0.Range.Fields)
if (field.Type == Aspose.Words.Fields.FieldType.FieldDocProperty && field.GetFieldCode().Contains(pair.Key))
builder.MoveToField(field, true);
builder.InsertDocument(new Document(pair.Value), ImportFormatMode.KeepSourceFormatting);

// Test if all tags are put in document
if (dico.Count != nbTag)
ConverterMessage myConvertMessage = ConverterMessage.CSCT_E_005;
throw new ConverterException(myConvertMessage, null);
d0.Save(@“D:\Temp\test insertdocx2docx\WORD_FINAL.docx”);



Hi Daniel,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you insert the contents of WORD_1.docx into WORD_2.docx at same place using MS Word, you will get the same output.

When you insert the contents with page break inside a table, the page breaks are removed from inserted contents. You are getting the expected behavior of Aspose.Words.

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Thanks for you answer.