Inserting or appending document or file in a word document programmatically using C#
Views (97)
Create a new windows application project and add a button to it.
On click of that button, we will create a new document and append or insert content of two documents in it.
First add reference to (Word 10.0 or 11.0 object library) within COM tab of Add reference dialog box.
After adding reference, add this directive
using Microsoft.Office.Interop.Word
Put this code on button click
// For optional parameters create a missing object
object missing = System.Reflection.Missing.Value;
// Create an object of application class
ApplicationClass WordApp = new ApplicationClass();
// add a document in the Application
Document adoc=WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
// declare variables for setting the position within the document
object start = 0;
object end = 0;
// create a range object which starts at 0
Range rng = adoc.Range(ref start, ref missing);
// insert a file
rng.InsertFile(@”C:\MyFirst.doc”, ref missing, ref missing, ref missing, ref missing);
// now make start to point to the end of the content of the first document
start = WordApp.ActiveDocument.Content.End – 1;
// create another range object with the new value for start
Range rng1 = adoc.Range(ref start, ref missing);
// insert the another document
rng1.InsertFile(@”C:\MySecond.doc”, ref missing, ref missing, ref missing, ref missing);
// now make start to point to the end of the content of the first document
start = WordApp.ActiveDocument.Content.End – 1;
// make the word appliction visible
WordApp.Visible = true;
Bye

This was originally posted here.
*This post is locked for comments