1+ using Syncfusion . DocIO ;
2+ using Syncfusion . DocIO . DLS ;
3+ using System . Runtime . Serialization ;
4+
5+ //Get the list of source document to be imported
6+ List < string > sourceFileNames = new List < string > ( ) ;
7+ sourceFileNames . Add ( "../../../Data/Addressblock.docx" ) ;
8+ sourceFileNames . Add ( "../../../Data/Salutation.docx" ) ;
9+ sourceFileNames . Add ( "../../../Data/Greetings.docx" ) ;
10+
11+ string destinationFileName = "../../../Data/Title.docx" ;
12+ using ( FileStream destinationStreamPath = new FileStream ( destinationFileName , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
13+ {
14+ //Opens the destination document
15+ using ( WordDocument destinationDocument = new WordDocument ( destinationStreamPath , FormatType . Automatic ) )
16+ {
17+ ImportOtherDocuments ( sourceFileNames , destinationDocument ) ;
18+ //Saves and closes the destination document
19+ using ( FileStream outputStream = new FileStream ( "../../../Data/Output.docx" , FileMode . Create , FileAccess . Write ) )
20+ {
21+ destinationDocument . Save ( outputStream , FormatType . Docx ) ;
22+ destinationDocument . Close ( ) ;
23+ }
24+ }
25+ }
26+
27+ void ImportOtherDocuments ( List < string > sourceFiles , WordDocument destinationDocument )
28+ {
29+ //Iterate through each source document from the list
30+ foreach ( string sourceFileName in sourceFiles )
31+ {
32+ //Open source document
33+ using ( FileStream sourceStreamPath = new FileStream ( sourceFileName , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
34+ {
35+ using ( WordDocument document = new WordDocument ( sourceStreamPath , FormatType . Automatic ) )
36+ {
37+ //Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
38+ document . LastSection . BreakCode = SectionBreakCode . NoBreak ;
39+ //Imports the contents of source document at the end of destination document
40+ destinationDocument . ImportContent ( document , ImportOptions . UseDestinationStyles ) ;
41+ //Close the document.
42+ document . Close ( ) ;
43+ }
44+ }
45+ }
46+ }
0 commit comments