Aspose.Words.Examples.CSharp.Programming_Documents.Joining_and_Appending.PrependDocument.DoPrepend C# (CSharp) Method

DoPrepend() public static method

public static DoPrepend ( Document dstDoc, Document srcDoc, ImportFormatMode mode ) : void
dstDoc Document
srcDoc Document
mode ImportFormatMode
return void
        public static void DoPrepend(Document dstDoc, Document srcDoc, ImportFormatMode mode)
        {
            // Loop through all sections in the source document. 
            // Section nodes are immediate children of the Document node so we can just enumerate the Document.
            ArrayList sections = new ArrayList(srcDoc.Sections.ToArray());

            // Reverse the order of the sections so they are prepended to start of the destination document in the correct order.
            sections.Reverse();

            foreach (Section srcSection in sections)
            {
                // Import the nodes from the source document.
                Node dstSection = dstDoc.ImportNode(srcSection, true, mode);

                // Now the new section node can be prepended to the destination document.
                // Note how PrependChild is used instead of AppendChild. This is the only line changed compared 
                // To the original method.
                dstDoc.PrependChild(dstSection);
            }
        }
    }
PrependDocument