A word processing file contains user information in plain text or rich text format. A plain text file format contains unformatted text and no font or page settings can be applied. In contrast, a rich text file format allows formatting options such as setting fonts type, styles (bold, italic, underline, etc.), page margins, headings, bullets and numbers, and several other formatting features. The use of plain text files have reduced significantly with passage of time as there are more powerful computers and programs available to offer rich text files processing.
Common plain text file extensions and associated file formats include TXT, CSV, while file extensions for rich text documents include DOCX, DOC and RTF.
How to merge DOCX documents
DOCX is a well-known format for Microsoft Word documents. Introduced from 2007 with the release of Microsoft Office 2007, the structure of this new Document format was changed from plain binary to a combination of XML and binary files. DOCX files can be opened with Word 2007 and lateral versions, but not with the earlier versions of MS Word which support DOC file extensions
Below is code snippet in C# that demonstrates how to merge DOCX files into single file.
// Load the source DOCX fileusing(Mergermerger=newMerger(@"c:\sample1.docx")){// Add another DOCX file to mergemerger.Join(@"c:\sample2.docx");// Merge DOCX files and save resultmerger.Save(@"c:\merged.docx");}
How to merge Word documents without starting from a new page
There is an additional option for Word document joining that allows to merge those documents without page breaking between them, i.e. the last page of the initial document will be merged with the first page of the next document as one page.
Below is code snippet in C# that demonstrates how to merge DOC files into single file without starting from a new page.
// Load the source DOC fileusing(Mergermerger=newMerger(@"c:\sample1.doc")){// Define Word join optionsWordJoinOptionsjoinOptions=newWordJoinOptions();joinOptions.Mode=WordJoinMode.Continuous;// Add another DOC file to mergemerger.Join(@"c:\sample2.doc",joinOptions);// Merge DOC files and save resultmerger.Save(@"c:\merged.doc");}
How to merge Word documents without section breaks
There is also another additional option for merging Word documents, which allows you to merge these documents without breaking sections, i.e. all sections and pages of all merged documents will be merged without breaks.
Below is code snippet in C# that demonstrates how to merge DOC files into single file without section breaks.
// Load the source DOC fileusing(Mergermerger=newMerger(@"c:\sample1.doc")){// Define Word join optionsWordJoinOptionsjoinOptions=newWordJoinOptions();joinOptions.Mode=WordJoinMode.DisableSectionBreaks;// Add another DOC file to mergemerger.Join(@"c:\sample2.doc",joinOptions);// Merge DOC files and save resultmerger.Save(@"c:\merged.doc");}
How to merge Word documents with pre-defined Compliance mode
There is an additional option for Word document joining that allows to merge those documents with pre-defined Compliance mode for the Word Ooxml formats such as .docx, .docm, .dotx, .dotm etc.
Below is code snippet in C# that demonstrates how to merge DOCX files into single file with ISO/IEC 29500:2008 Strict compliance level.
// Load the source DOCX fileusing(Mergermerger=newMerger(@"c:\sample1.docx")){// Define Word join optionsWordJoinOptionsjoinOptions=newWordJoinOptions();joinOptions.Compliance=WordJoinCompliance.Iso29500_2008_Strict;// Add another DOCX file to mergemerger.Join(@"c:\sample2.docx",joinOptions);// Merge DOCX files and save resultmerger.Save(@"c:\merged.docx");}
How to merge TXT files
A file with .TXT extension represents a text document that contains plain text in the form of lines. Paragraphs in a text document are recognized by carriage returns and are used for better arrangement of file contents. A standard text document can be opened in any text editor or word processing application on different operating systems. All the text contained in such a file is in human-readable format and represented by a sequence of characters.
You can combine any number of text files like shows this C# code sample:
// Load the source TXT fileusing(Mergermerger=newMerger(@"c:\sample1.txt")){// Add another TXT file to mergemerger.Join(@"c:\sample2.txt");// Merge TXT files and save resultmerger.Save(@"c:\merged.txt");}
How to merge RTF files
Introduced and documented by Microsoft, the Rich Text Format (RTF) represents a method of encoding formatted text and graphics for use within applications. The format facilitates cross-platform document exchange with other Microsoft Products, thus serving the purpose of interoperability. This capability makes it a standard of data transfer between word processing software and, hence, contents can be transferred from one operating system to another without losing document formatting.
Joining multiple RTF documents into one is pretty the same as for any other formats - just specify files you want to merge and save the resultant document.
// Load the source RTF fileusing(Mergermerger=newMerger(@"c:\sample1.rtf")){// Add another RTF file to mergemerger.Join(@"c:\sample2.rtf");// Merge RTF files and save resultmerger.Save(@"c:\merged.rtf");}