Embedding another word file to a word document programmatically

Hi

Many a times we want to embed some document in the word file, with the help of Insert-> File-> Select File menu item. This will copy the content of the file to the word document. This can also be done programmatically. 

String LocationOfFileToMerge = "C:\\Myfile.doc";

range.InsertFile(LocationOfFileToMerge,ref oMissing, ref oFalse, ref oFalse, ref oFalse);

We can also embed the document in the word file instead of copying the text of the document. In this case you can embed any kind of document.


Object NameForLabel = "File Name";

 

//Icon To Be Shown For Label
Object IconFileName = "C:\\IconFile.ico";

 

String LocationOfFileToMerge = "C:\\Myfile.doc";

Object ClassType = "Word.Document.8";

Object True = true;

Object False = false;

Object Missing = System.Reflection.Missing.Value;

 

range.InlineShapes.AddOLEObject(

    ref ClassType,ref LocationOfFileToMerge,ref False, ref True, ref IconFileName,

    ref Missing,ref NameForLabel, ref Missing);

Vikram

No Comments